- iOS 8.0+
- macOS 10.10+
- tvOS 9.0+
- watchOS 3.0+
SKAction object is an action that is executed by a node in the scene (
SKScene). Actions are most often used to change the structure and content of the node to which they are attached but can also make other changes to the scene. When the scene processes its nodes, actions associated with those nodes are evaluated.To create an action, call the class method for the action you are interested in. Then, configure the action’s properties. Finally, to execute the action, call a node object’s
run(_:) method (or a similar method on the
SKNode class) and pass it the action object.
Most actions allow you to change a node’s properties, such as its position, rotation, or scale. Some actions specifically apply only to
SKSpriteNode objects, allowing you to animate a sprite’s color or texture properties. Many of these actions are animated by Sprite Kit, meaning that they change the properties of the associated node over more than one frame of animation rendered by the scene. When an action is animated, the
duration property states how long that action takes to complete in seconds and its
timingMode property defines the rate at which the animation executes. The action’s
speed property allows you to adjust the timing of the animation by increasing or decreasing its playback speed.
Many actions can be reversed, allowing you to create another action object that reverses the effect of that action. For example, if an action object moves a node
20 points to the right of its current position, the reversed action moves the node
20 points to the left. To create a reversed action object, call an action object’s
Some actions include other actions as children:
A sequence action has multiple child actions. Each action in the sequence begins after the previous action ends.
A group action has multiple child actions. All actions stored in the group begin executing at the same time.
A repeating action stores a single child action. When the child action completes, it is restarted.
Groups, sequences, and repeating actions can be nested. The ability to combine actions together allows you to add very sophisticated behaviors to a node.
You never subclass
SKAction directly. Instead, create actions that call methods on arbitrary objects or execute blocks of code. See Creating Custom Actions.