3

Im trying to add a kind of background to a label node in my swift game.

imagine my background moving with white clouds, but i want to show the score in the top middle of the scene, everytime a cloud passes the score doesn't show (as i want the text to be white).

I thought i could add an SKSpriteNode behind the label with a low .alpha property and achieve what i wanted. However, as the label grows bigger and bigger with the score going up it goes out of the SKNodes bounds if you will. If i start with a big background it looks silly.

Does this make sense? So far i kind of have this:

    // Create the score label
func createLabel() {

    let behindLabelNode = SKSpriteNode()

        behindLabelNode.color = SKColor.black
        behindLabelNode.alpha = 0.5
        behindLabelNode.zPosition = 4
        behindLabelNode.position = CGPoint(x: 0, y: (self.frame.size.height / 2.5))
        behindLabelNode.size = CGSize(width: 200, height: 120)
        self.addChild(behindLabelNode)
    } else {
        behindLabelNode.color = SKColor.black
        behindLabelNode.alpha = 0.5
        behindLabelNode.zPosition = 4
        behindLabelNode.position = CGPoint(x: 0, y: (self.frame.size.height / 2.5))
        behindLabelNode.size = CGSize(width: 120, height: 120)
        self.addChild(behindLabelNode)
    }


    scoreLabel = SKLabelNode(fontNamed: "Lockergnome")
    scoreLabel.zPosition = 6
    scoreLabel.position = CGPoint(x: 0, y: (self.frame.size.height) / 2.8)
    scoreLabel.fontSize = 120
    scoreLabel.fontColor = SKColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
    scoreLabel.text = "0"
    self.addChild(scoreLabel)

}
cristallo
  • 1,951
  • 2
  • 25
  • 42
LukeTerzich
  • 555
  • 1
  • 4
  • 17
  • What you could do is each time you increase the score, check if the amount of numbers changed(i.e. from 9 to 10 for example) and then increase `behindLabelNode` size? To show you exactly how I need to have the code where the labelText changes – Eric May 22 '17 at 17:55
  • Good thinking! Once I'm at my pc again I will edit my question! – LukeTerzich May 23 '17 at 10:31
  • updated code, this doesn't work it stays the same size – LukeTerzich May 24 '17 at 15:05
  • As I said could you provide me with more code? ( the part were you increase the score of the label) Also there is a random `else` in your code – Eric May 25 '17 at 18:40

0 Answers0