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)
}