sprite-kit Named actions that can be started or removed from elsewhere.


Example

Sometimes you would want to start or remove an action on a specific node at a certain time. For example, you might want to stop a moving object when the user taps the screen. This becomes very helpful when a node has multiple actions and you only wants to access one of them.

let move = SKAction.moveTo(x: 200, duration: 2)
object.run(move, withKey: "moveX")

Here we set the key "moveX" for the action move in order to access it later in another part of the class.

  override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        object.removeAction(forKey: "moveX")
    }

When the user touches the screen the action will get removed and the object will stop moving.