Search code examples
swiftanimationsprite-kitfadesklabelnode

Fade animation for SKLabelNode changing text


Okay so I have implemented a simple SKLabelNode with some text.

I want to add a fade animation when I change the text.

I know there is an easy way to do it with UILabels but I cant figure out how to do it with SKLabels.


Solution

  • You need to run an SKAction (fade) on it

    let label = SKLabelNode(...
    label.fontSize = ...
    label.fontColor = ...
    label.position = ...
    addChild(label)
    
    let fadeAction = SKAction.fadeAlphaTo(0.5, duration: 1)
    label.runAction(fadeAction)
    

    Hope that helps