SKAction

Overview

  • Single class: SKAction
  • As a role of Façade
  • Chainable, reusable, readable
  • Looks like scripting language

Running Actions

  • Run action immediately
  • Copy on add, remove on completion
  • Can be repeated N times or forever

Sequences

let action1 = SKAction.scaleX(to: 1.0, duration: 1.0)
let action2 = SKAction.fadeAlpha(to: 1.0, duration: 2.0)
let action3 = SKAction.move(to: newPos, duration: 0.5)
let actionSequence = SKAction.sequence([action1, action2, action3])
self.run(actionSequence)
Sequence

Groups

let action1 = SKAction.scaleX(to: 1.0, duration: 1.0)
let action2 = SKAction.fadeAlpha(to: 1.0, duration: 2.0)
let action3 = SKAction.move(to: newPos, duration: 0.5)
let actionSequence = SKAction.group([action1, action2, action3])
self.run(actionSequence)
Group

Sequence With Group

Sequence with Group

Timing

let wait = SKAction.wait(forDuration: 1.0)
let sequence = SKAction.sequence([wait, action1])
Delayed Sequence

Speciality

  • Animate with textures
  • Animate with a path (CGPath)
  • Fade in/out, remove from parent
  • Short sounds playback