I want to know is there a way to set background color for a SKLabelNode not font color. I'm looking for something like below mentioned code, which is available in ios apps.
label.backgroundColor = [UIColor redColor];
Adding the SKLabelNode as a child of a SKSpriteNode works but it hides the text. So, I resolved this issue by setting the zPosition of background to a negative number. Here is the swift 3 code:
var label = SKLabelNode(fontNamed: "Helvetica")
label.position = CGPoint(x: CGFloat(0), y: CGFloat(-label.frame.size.height / 2))
var background = SKSpriteNode(color: UIColor.red, size: CGSize(width: CGFloat(label.frame.size.width), height:CGFloat(label.frame.size.height)))background.position = CGPoint(x: CGFloat(200), y: CGFloat(100))
background.zPosition = -1
label.addChild(background)
self.addChild(label)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With