Action Initializers

Use these functions to create actions.

Overview

Most actions implement specific predefined animations that are done for you by SpriteKit. If your animation needs fall outside of the suite provided here, then you should:

Choose an Initializer for the Property You Want to Alter

Most actions allow you to change a node’s properties and some actions specifically apply to specific nodes, like SKSpriteNode's actions for animating its color or texture.

Here are the most common animated properties:

  • Changing a node’s position and zRotation

  • Changing a node’s size or scaling properties

  • Changing a node’s visibility or making it translucent

  • Changing a sprite node’s contents so that it animates through a series of textures

  • Colorizing a sprite node

  • Playing sounds

  • Removing a node from the node tree

  • Calling a block

  • Invoking a selector on an object

See Action Initializers for a full list of action types.

Chaining Actions

Actions can be chained together in multiple ways:

  • 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.

To delay a subsequent action in the chain, insert a waitForDuration: action in the sequence, and remember that groups, sequences, and repeating actions may be nested.

Topics

Animating a Node's Position in a Linear Path

Animate linear node movement.

+ moveByX:y:duration:

Creates an action that moves a node relative to its current position.

+ moveBy:duration:

Creates an action that moves a node relative to its current position.

+ moveTo:duration:

Creates an action that moves a node to a new position.

+ moveToX:duration:

Creates an action that moves a node horizontally.

+ moveToY:duration:

Creates an action that moves a node vertically.

Animating a Node's Position Along a Custom Path

Provide a path for the node to follow.

+ followPath:duration:

Creates an action that moves the node along a relative path, orienting the node to the path.

+ followPath:speed:

Creates an action that moves the node along a relative path at a specified speed, orienting the node to the path.

+ followPath:asOffset:orientToPath:duration:

Creates an action that moves the node along a path.

+ followPath:asOffset:orientToPath:speed:

Creates an action that moves the node at a specified speed along a path.

Animating the Rotation of a Node

Animate the z rotation of a node. If instead you wish to change the x or y rotation of a node, see SKTransformNode.

+ rotateByAngle:duration:

Creates an action that rotates the node by a relative value.

+ rotateToAngle:duration:

Creates an action that rotates the node counterclockwise to an absolute angle.

+ rotateToAngle:duration:shortestUnitArc:

Creates an action that rotates the node to an absolute value.

Controling the Action's Speed

Control the speed of an animation.

+ speedBy:duration:

Creates an action that changes how fast the node executes actions by a relative value.

+ speedTo:duration:

Creates an action that changes how fast the node executes actions.

Animating the Scaling of a Node

Animate the visual scaling of a node.

+ scaleBy:duration:

Creates an action that changes the x and y scale values of a node by a relative value.

+ scaleToSize:duration:

Creates an action that changes the x and y scale values of a node to achieve

+ scaleTo:duration:

Creates an action that changes the x and y scale values of a node.

+ scaleXBy:y:duration:

Creates an action that adds relative values to the x and y scale values of a node.

+ scaleXTo:y:duration:

Creates an action that changes the x and y scale values of a node.

+ scaleXTo:duration:

Creates an action that changes the x scale value of a node to a new value.

+ scaleYTo:duration:

Creates an action that changes the y scale value of a node to a new value.

Animating the Transparency of a Node

Gradually change a node's transparency.

+ fadeInWithDuration:

Creates an action that changes the alpha value of the node to 1.0.

+ fadeOutWithDuration:

Creates an action that changes the alpha value of the node to 0.0.

+ fadeAlphaBy:duration:

Creates an action that adjusts the alpha value of a node by a relative value.

+ fadeAlphaTo:duration:

Creates an action that adjusts the alpha value of a node to a new value.

Animating a Node's Texture

Change a node's texture or the texture's properties.

+ resizeByWidth:height:duration:

Creates an action that adjusts the size of a sprite.

+ resizeToHeight:duration:

Creates an action that changes the height of a sprite to a new absolute value.

+ resizeToWidth:duration:

Creates an action that changes the width of a sprite to a new absolute value.

+ resizeToWidth:height:duration:

Creates an action that changes the width and height of a sprite to a new absolute value.

+ setTexture:

Creates an action that changes a sprite’s texture.

+ setTexture:resize:

Creates an action that changes a sprite’s texture, possibly resizing the sprite.

+ animateWithTextures:timePerFrame:

Creates an action that animates changes to a sprite’s texture.

+ animateWithTextures:timePerFrame:resize:restore:

Creates an action that animates changes to a sprite’s texture, possibly resizing the sprite.

+ setNormalTexture:

Creates an action that changes a sprite’s normal texture.

+ setNormalTexture:resize:

Creates an action that changes a sprite’s normal texture, possibly resizing the sprite.

+ animateWithNormalTextures:timePerFrame:

Creates an action that animates changes to a sprite’s normal texture.

+ animateWithNormalTextures:timePerFrame:resize:restore:

Creates an action that animates changes to a sprite’s texture.

+ colorizeWithColor:colorBlendFactor:duration:

Creates an animation that animates a sprite’s color and blend factor.

+ colorizeWithColorBlendFactor:duration:

Creates an action that animates a sprite’s blend factor.

Animating Properties of a Node's Physics Body

Physics actions are instantaneous and therefore more useful when Chaining Actions or Reuse Actions.

+ applyForce:duration:

Creates an action that applies a force to the center of gravity of a node’s physics body.

+ applyTorque:duration:

Creates an action that applies a torque to a node’s physics body.

+ applyForce:atPoint:duration:

Creates an action that applies a force to a specific point on a node’s physics body.

+ applyImpulse:duration:

Creates an action that applies an impulse to the center of gravity of a physics body.

+ applyAngularImpulse:duration:

Creates an action that applies an angular impulse to a node’s physics body.

+ applyImpulse:atPoint:duration:

Creates an action that applies an impulse to a specific point of a node’s physics body.

+ changeChargeTo:duration:

Creates an action that changes the charge of a node’s physics body to a new value.

+ changeChargeBy:duration:

Creates an action that changes the charge of a node’s physics body by a relative value.

+ changeMassTo:duration:

Creates an action that changes the mass of a node’s physics body to a new value.

+ changeMassBy:duration:

Creates an action that changes the mass of a node’s physics body by a relative value.

+ strengthTo:duration:

Creates an action that animates a change of a physics field’s strength.

+ strengthBy:duration:

Creates an action that animates a change of a physics field’s strength to a value relative to the existing value.

+ falloffTo:duration:

Creates an action that animates a change of a physics field’s falloff.

+ falloffBy:duration:

Creates an action that animates a change of a physics field’s falloff to a value relative to the existing value.

Reversing an Animation

Create a new action that is the opposite of another action.

- reversedAction

Creates an action that reverses the behavior of another action.

Animate the Warping of a Node

Interpolate the warping of a node over time.

+ animateWithWarps:times:

Creates an action to distort a node through a sequence of SKWarpGeometry objects.

+ animateWithWarps:times:restore:

Creates an action to distort a node through a sequence of SKWarpGeometry objects.

+ warpTo:duration:

Creates an action to distort a node based using an SKWarpGeometry object.

Conrolling the Audio of a Node

Audio actions are instantaneous and so, more useful when Chaining Actions or Reuse Actions.

+ playSoundFileNamed:waitForCompletion:

Creates an action that plays a sound.

+ play

Creates an action that tells an audio node to start playback.

+ pause

Creates an action that tells an audio node to pause playback.

+ stop

Creates an action that tells an audio node to stop playback.

+ changePlaybackRateTo:duration:

Creates an action that changes an audio node’s playback rate to a new value.

+ changePlaybackRateBy:duration:

Creates an action that changes an audio node’s playback rate by a relative amount.

+ changeVolumeTo:duration:

Creates an action that changes an audio node’s volume to a new value.

+ changeVolumeBy:duration:

Creates an action that changes an audio node’s volume by a relative value.

+ changeObstructionTo:duration:

Creates an action that changes an audio node’s obstruction to a new value.

+ changeObstructionBy:duration:

Creates an action that changes an audio node’s obstruction by a relative value.

+ changeOcclusionTo:duration:

Creates an action that changes an audio node’s occlusion to a new value.

+ changeOcclusionBy:duration:

Creates an action that changes an audio node’s occlusion by a relative value.

+ changeReverbTo:duration:

Creates an action that changes an audio node’s reverb to a new value.

+ changeReverbBy:duration:

Creates an action that changes an audio node’s reverb by a relative value.

+ stereoPanTo:duration:

Creates an action that changes an audio node’s stereo panning to a new value.

+ stereoPanBy:duration:

Creates an action that changes an audio node’s stereo panning by a relative value.

Removing a Node from the Scene

Instantaneous action that is useful when Chaining Actions or Reuse Actions.

+ removeFromParent

Creates an action that removes the node from its parent.

Running Actions on Children

Run an action on a child node by its name.

+ runAction:onChildWithName:

Creates an action that runs an action on a named child object.

Chaining Actions

Create an action that contains a series, or chain, of other actions.

+ group:

Creates an action that runs a collection of actions in parallel.

+ sequence:

Creates an action that runs a collection of actions sequentially.

+ repeatAction:count:

Creates an action that repeats another action a specified number of times.

+ repeatActionForever:

Creates an action that repeats another action forever.

Delaying Actions

Delay a subseqent action in a sequence of other actions.

+ waitForDuration:

Creates an action that idles for a specified period of time.

+ waitForDuration:withRange:

Creates an action that idles for a randomized period of time.

Performing Inverse Kinematics

Working with Inverse Kinematics

Gain fine-tuned control of objects that are connected by joints.

+ reachTo:rootNode:duration:

Creates an action that performs an inverse kinematic reach.

+ reachTo:rootNode:velocity:

Creates an action that performs an inverse kinematic reach.

+ reachToNode:rootNode:duration:

Creates an action that performs an inverse kinematic reach.

+ reachToNode:rootNode:velocity:

Creates an action that performs an inverse kinematic reach.

Creating Custom Actions

Provide code that implements your own action.

+ actionNamed:

Creates an action of the given name from an action file.

+ actionNamed:duration:

Creates an action of the given name from an action file with a new duration.

+ actionNamed:fromURL:

Creates an action of the given name from an action file.

+ actionNamed:fromURL:duration:

Creates an action of the given name from an action file with a new duration.

+ customActionWithDuration:actionBlock:

Creates an action that executes a block over a duration.

+ performSelector:onTarget:

Creates an action that calls a method on an object.

+ runBlock:

Creates an action that executes a block.

+ runBlock:queue:

Creates an action that executes a block on a specific dispatch queue.

Controlling Node Visibility

Control a node's visibility.

+ unhide

Creates an action that makes a node visible.

+ hide

Creates an action that hides a node.

See Also

First Steps

Getting Started with Actions

Create, configure, and run actions in SpriteKit.