1

I have SKLabelNode in my Swift-code. I need to change the Label's color during SKAction. Simply:

override func didMoveToView(view: SKView) {
...
var color = UIColor(red: CGFloat(1.0), green: CGFloat(0.0), blue: CGFloat(0.0), alpha: CGFloat(0.0))
myLabel.fontColor = color
...
}

Doesn't work. I still have to somehow update the node but how? I'm noobie to Swift and Sprite Kit.

user3673836
  • 591
  • 1
  • 9
  • 23

2 Answers2

4

Do you need it to be in an SKAction? If not, simply use this:

myLabel.fontColor =  SKColor.blueColor()

Substitute blueColor with whichever color you want, or use the generic method where 'float here' is a fraction of 255 (such as 50.0f/255.0f).

myLabel.fontColor = SKColor(red: floatHere, green: floatHere, blue: floatHere, alpha: floatFrom0To1Here)

In case you do need to set the color through an SKAction, you can use this method:

myLabel.runAction(SKAction.colorizeWithColor(UIColor.blueColor(), colorBlendFactor: 1, duration: 1))
Andriko13
  • 992
  • 1
  • 7
  • 34
0

I had a similar problem a few weeks ago. Try changing your color variable to the following:

var color = UIColor(red: 1.0 / 255, green: 0.0 / 255, blue: 0.0 / 255, alpha: 0.0)
Reece Kenney
  • 2,734
  • 3
  • 24
  • 57