Reputation: 599
I have the following code, which doesn't seem to set the text color of scoreLabelNode to red.
func setUpScore() -> Void {
scoreLabelNode = SKLabelNode(fontNamed:"MarkerFelt-Wide")
scoreLabelNode.color = UIColor(red: CGFloat(1.0), green: CGFloat(0.0), blue: CGFloat(0.0), alpha: CGFloat(1.0)) //How do I set this to red?
scoreLabelNode.position = CGPointMake( CGRectGetMidX( self.frame ), 0.5)
scoreLabelNode.zPosition = 100
scoreLabelNode.text = String(score)
self.addChild(scoreLabelNode)
}
How would I change the second line to get the score to display as red?
Upvotes: 3
Views: 2261
Reputation: 23400
Try (note the 'fontColor', not 'color')
scoreLabelNode.fontColor = UIColor.redColor()
Upvotes: 10
Reputation: 5896
UIColor - UIColor(red:R, green: G, blue: B, alpha: A)
R,G,B are values between 0.0 to 1.0. When A stand to alpha(as well between 0.0 to 1.0).
Use this site to calculate the needed RGBA values : http://www.colorpicker.com/
As for red, just change it to
scoreLabelNode.color = UIColor(red: 255/255, green: 0, blue: 0, alpha: 1)
OR
scoreLabelNode.color = UIColor.redColor()
Try replacing
scoreLabelNode.color
To
**scoreLabelNode.fontColor**
Upvotes: 1