建立重複的動作序列

有時需要重複或按順序執行操作。此示例將使節點淡入和淡出總共 3 次。

在 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)