MysteryPancake MysteryPancake - 1 month ago 20
Swift Question

Swift: SKLabelNode fade animation doesn't fade

I'm just trying to make a SKLabelNode fade in, here's my code:

let welcome = SKLabelNode(text: "Welcome")
welcome.fontName = "HelveticaNeue-Light"
welcome.fontSize *= size.width/welcome.frame.width
welcome.fontColor = UIColor(white:1,alpha:0)
welcome.horizontalAlignmentMode = .center
welcome.verticalAlignmentMode = .center
welcome.position = CGPoint(x:size.width/2,y:size.height/2)
addChild(welcome)

let fadein = SKAction.fadeIn(withDuration: 1)
let remove = SKAction.removeFromParent()
welcome.run(SKAction.sequence([fadein,remove]))


But it doesn't work, and I can't figure out why. The strange part is the removeFromParent part works fine, just not the fade in. I already tried changing the font, making the label fade out and even making a custom action that changes the alpha, all of which have failed. I just can't figure out what the problem is.

Answer

Set the SKLabelNode's alpha to 0 before running the fadeIn() action on it.