sprite-kit Creating a Repeating Sequence of Actions


Example

Sometimes it is necessary to do an action on repeat or in a sequence. This example will make the node fade in and out a total of 3 times.

In Swift:

let node = SKSpriteNode(imageNamed: "image")
let actionFadeOut = SKAction.fadeOutWithDuration(1.0)
let actionFadeIn = SKAction.fadeInWithDuration(1.0)
let actionSequence = SKAction.sequence([actionFadeOut, actionFadeIn])
let actionRepeat = SKAction.repeatAction(actionSequence, count: 3)
node.runAction(actionRepeat)