SKAction Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/SpriteKit.framework
Availability
Available in iOS 7.0 and later.
Companion guide
Declared in
SKAction.h

Overview

An 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 runAction: 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 reversedAction method.

Some actions include other actions as children:

Groups, sequences, and repeating actions can be nested. The ability to combine actions together allows you to add very sophisticated behaviors to a node.

Subclassing Notes

You never subclass SKAction directly. Instead, create actions that call methods on arbitrary objects or execute blocks of code. See “Creating Custom Actions.”

Tasks

Creating Actions That Move Nodes

Creating Actions That Rotate Nodes

Creating Actions That Change a Node’s Animation Speed

Creating Actions That Change a Node’s Scale

Creating Actions That Change a Node’s Transparency

Creating Actions That Change a Sprite Node’s Content

Playing Sounds

Removing Nodes from the Scene

Creating Actions That Perform Actions on a Node’s Child

Creating Actions That Combine or Repeat Other Actions

Creating an Action to Introduce a Delay into a Sequence

Creating Custom Actions

Reversing an Action

Inspecting an Action’s Animation Properties

Properties

duration

The duration required to complete an action.

@property(nonatomic) NSTimeInterval duration
Discussion

This is the expected duration of an action’s animation. The actual time an action takes to complete is modified by the speed property of the action and the speed property of the node on which it executes.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

speed

A speed factor that modifies how fast an action runs.

@property(nonatomic) CGFloat speed
Discussion

The speed factor adjusts how fast an action’s animation runs. For example, a speed factor of 2.0 means the animation runs twice as fast.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

timingMode

The timing mode used to execute an action.

@property(nonatomic) SKActionTimingMode timingMode
Discussion

The possible values for this property are listed in “Action Timing Modes”. The default value is SKActionTimingLinear.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

Class Methods

animateWithTextures:timePerFrame:

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

+ (SKAction *)animateWithTextures:(NSArray *)textures timePerFrame:(NSTimeInterval)sec
Parameters
textures

An array of textures to use when animating a sprite.

sec

The amount of time that each texture is displayed.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s texture property animates through the array of textures. The sprite’s texture property is changed to the next texture in the array. The action then pauses for the specified time before continuing. The action continues until it has finished animating through all of the textures in the array. The total duration of the action is the number of textures multiplied by the frame interval.

This action is reversible; the resulting action animates through the same textures from last to first.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

animateWithTextures:timePerFrame:resize:restore:

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

+ (SKAction *)animateWithTextures:(NSArray *)textures timePerFrame:(NSTimeInterval)sec resize:(BOOL)resize restore:(BOOL)restore
Parameters
textures

An array of textures to use when animating a sprite.

sec

The time that each texture is displayed.

resize

If YES, the sprite is resized to match each new texture. If NO, the size of the sprite remains at a constant size.

restore
  • If YES:

    When the action completes, the sprite’s texture is restored to the texture it had before the action completed. (If the resize parameter is YES, the sprite is resized to match the size of the original texture.

  • If NO:

    When the action completes the sprite’s texture remains set to the final texture in the array.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s texture property animates through the array of textures. The sprite’s texture property is changed to the next texture in the array. The action then pauses for the specified time before continuing. The action continues until it has finished animating through all of the textures in the array. The total duration of the action is the number of textures multiplied by the frame interval.

This action is reversible; the resulting action animates through the same textures from last to first.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

colorizeWithColor:colorBlendFactor:duration:

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

+ (SKAction *)colorizeWithColor:(SKColor *)color colorBlendFactor:(CGFloat)colorBlendFactor duration:(NSTimeInterval)sec
Parameters
color

The new color for the sprite.

colorBlendFactor

The new blend factor for the sprite.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s color and colorBlendFactor properties are animated to their new values.

This action is not reversible; the reverse of this action does nothing.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

colorizeWithColorBlendFactor:duration:

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

+ (SKAction *)colorizeWithColorBlendFactor:(CGFloat)colorBlendFactor duration:(NSTimeInterval)sec
Parameters
colorBlendFactor

The new blend factor for the sprite.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s colorBlendFactor property animates to the new value.

This action is not reversible; the reverse of this action does nothing.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

customActionWithDuration:actionBlock:

Creates an action that executes a block over a duration.

+ (SKAction *)customActionWithDuration:(NSTimeInterval)seconds actionBlock:(void (^)(SKNode *node, CGFloat elapsedTime))block
Parameters
seconds

The duration of the action, in seconds.

block

The block to run. The block takes the following parameters:

node

The node on which the action is running.

elapsedTime

The amount of time that has passed in the animation.

Return Value

A new action object.

Discussion

When the action executes, the block is called repeatedly until the action’s duration expires. The elapsed time is computed and passed to the block whenever the block is called.

This action is not reversible; the reverse action executes the same block.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

fadeAlphaBy:duration:

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

+ (SKAction *)fadeAlphaBy:(CGFloat)factor duration:(NSTimeInterval)sec
Parameters
factor

The amount to add to the node’s alpha value.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s alpha property animates to its new value.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction fadeAlphaBy: -factor duration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

fadeAlphaTo:duration:

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

+ (SKAction *)fadeAlphaTo:(CGFloat)alpha duration:(NSTimeInterval)sec
Parameters
alpha

The new value of the node’s alpha.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s alpha property animates to its new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

fadeInWithDuration:

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

+ (SKAction *)fadeInWithDuration:(NSTimeInterval)sec
Parameters
sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s alpha property animates from its current value to 1.0.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction fadeOutWithDuration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

fadeOutWithDuration:

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

+ (SKAction *)fadeOutWithDuration:(NSTimeInterval)sec
Parameters
sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s alpha property animates from its current value to 0.0. This causes the node to disappear.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction fadeInWithDuration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

followPath:asOffset:orientToPath:duration:

Creates an action that moves the node along a path.

+ (SKAction *)followPath:(CGPathRef)path asOffset:(BOOL)offset orientToPath:(BOOL)orient duration:(NSTimeInterval)sec
Parameters
path

A path to follow.

offset

If YES, the points in the path are relative offsets to the node’s starting position. If NO, the points in the node are absolute coordinate values.

orient

If YES, the node’s zRotation property animates so that the node turns to follow the path. If NO, the zRotation property of the node is unchanged.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s position and zRotation properties are animated along the provided path.

This action is reversible; the resulting action creates a reversed path and then follows it, with the same duration.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

followPath:duration:

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

+ (SKAction *)followPath:(CGPathRef)path duration:(NSTimeInterval)sec
Parameters
path

A Core Graphics path whose coordinates are relative to the node’s current position.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

Calling this method is equivalent to calling the followPath:asOffset:orientToPath:duration: method, passing in YES to both the offset and orient parameters.

This action is reversible; the resulting action creates and then follows a reversed path with the same duration.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

group:

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

+ (SKAction *)group:(NSArray *)actions
Parameters
actions

An array of SKAction objects.

Return Value

A group action object.

Discussion

When the action executes, the actions that comprise the group all start immediately and run in parallel. The duration of the group action is the longest duration among the collection of actions. If an action in the group has a duration less than the group’s duration, the action completes, then idles until the group completes the remaining actions. This matters most when creating a repeating action that repeats a group.

This action is reversible; it creates a new group action that contains the reverse of each action specified in the group.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

moveBy:duration:

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

+ (SKAction *)moveBY:(CGVector)delta duration:(NSTimeInterval)sec
Parameters
delta

A vector that describes the change to apply to the node’s position.

sec

The duration of the animation.

Return Value

A new move action.

Discussion

When the action executes, the node’s position property animates from its current position to its new position.

This action is reversible; the reverse is created as if the following code were executed:

CGVector negDelta = CGVectorMake(-delta.dx,-delta.dy);
[SKAction moveBY: negDelta duration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

moveByX:y:duration:

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

+ (SKAction *)moveByX:(CGFloat)deltaX y:(CGFloat)deltaY duration:(NSTimeInterval)sec
Parameters
deltaX

The x-value, in points, to add to the node’s position.

deltaY

The y-value, in points, to add to the node’s position.

sec

The duration of the animation.

Return Value

A new move action.

Discussion

When the action executes, the node’s position property animates from its current position to its new position.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction moveByX: -deltaX y: -deltaY duration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

moveTo:duration:

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

+ (SKAction *)moveTo:(CGPoint)location duration:(NSTimeInterval)sec
Parameters
location

The coordinates for the node’s new position.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s position property animates from its current position to its new position.

This action is not reversible; the reverse of this action has the same duration but does not move the node.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

moveToX:duration:

Creates an action that moves a node horizontally.

+ (SKAction *)moveToX:(CGFloat)x duration:(NSTimeInterval)sec
Parameters
x

The x-value for the node’s new position.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s position property animates from its current position to its new position.

This action is not reversible; the reverse of this action has the same duration but does not move the node.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

moveToY:duration:

Creates an action that moves a node vertically.

+ (SKAction *)moveToY:(CGFloat)y duration:(NSTimeInterval)sec
Parameters
y

The y-value for the node’s new position.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s position property animates from its current position to its new position.

This action is not reversible; the reverse of this action has the same duration but does not move the node.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

performSelector:onTarget:

Creates an action that calls a method on an object.

+ (SKAction *)performSelector:(SEL)selector onTarget:(id)target
Parameters
selector

The selector of the method to call.

target

The target object.

Return Value

A new action object.

Discussion

The action object maintains a strong reference to the target object.

When the action executes, the target object’s method is called. This action occurs instantaneously.

This action is not reversible; the reverse of this action calls the selector again.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

playSoundFileNamed:waitForCompletion:

Creates an action that plays a sound.

+ (SKAction *)playSoundFileNamed:(NSString *)soundFile waitForCompletion:(BOOL)wait
Parameters
soundFile

The name of a sound file in the app’s bundle.

wait

If YES, then the duration of this action is the same as the length of the audio playback. If NO, the action is considered to have completed immediately.

Return Value

A new action object.

Discussion

This action is not reversible; the reversed action is identical to the original action.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

removeFromParent

Creates an action that removes the node from its parent.

+ (SKAction *)removeFromParent
Return Value

A new action object.

Discussion

When the action executes, the node is immediately removed from its parent.

This action is not reversible; the reverse of this action is the same action.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

repeatAction:count:

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

+ (SKAction *)repeatAction:(SKAction *)action count:(NSUInteger)count
Parameters
action

The action to execute.

count

The number of times to execute the action.

Return Value

A new action object.

Discussion

When the action executes, the associated action runs to completion and then repeats, until the count is reached.

This action is reversible; it creates a new action that is the reverse of the specified action and then repeats it the same number of times.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

repeatActionForever:

Creates an action that repeats another action forever.

+ (SKAction *)repeatActionForever:(SKAction *)action
Parameters
action

The action to execute.

Return Value

A new action object.

Discussion

When the action executes, the associated action runs to completion and then repeats.

This action is reversible; it creates a new action that is the reverse of the specified action and then repeats it forever.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

resizeByWidth:height:duration:

Creates an action that adjusts the size of a sprite.

+ (SKAction *)resizeByWidth:(CGFloat)width height:(CGFloat)height duration:(NSTimeInterval)duration
Parameters
width

The amount to add to the sprite’s width.

height

The amount to add to the sprite’s height.

duration

The duration of the animation.

Return Value

A new action object.

Discussion

This action can only be executed by a SKSpriteNode object. When the action executes, the sprite’s size property animates to its new value.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction resizeByWidth: -width height: -height duration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

resizeToHeight:duration:

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

+ (SKAction *)resizeToHeight:(CGFloat)height duration:(NSTimeInterval)duration
Parameters
height

The new height of the sprite.

duration

The duration of the animation.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s size property animates to its new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

resizeToWidth:duration:

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

+ (SKAction *)resizeToWidth:(CGFloat)width duration:(NSTimeInterval)duration
Parameters
width

The new width of the sprite.

duration

The duration of the animation.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s size property animates to its new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

resizeToWidth:height:duration:

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

+ (SKAction *)resizeToWidth:(CGFloat)width height:(CGFloat)height duration:(NSTimeInterval)duration
Parameters
width

The new width of the sprite.

height

The new height of the sprite.

duration

The duration of the animation.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s size property animates to its new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

rotateByAngle:duration:

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

+ (SKAction *)rotateByAngle:(CGFloat)radians duration:(NSTimeInterval)sec
Parameters
radians

The amount to rotate the node, in radians.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s zRotation property animates to the new angle.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction rotateByAngle: -radians duration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

rotateToAngle:duration:

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

+ (SKAction *)rotateToAngle:(CGFloat)radians duration:(NSTimeInterval)sec
Parameters
radians

The angle to rotate the node to, in radians.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s zRotation property is interpolated to the new angle.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

rotateToAngle:duration:shortestUnitArc:

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

+ (SKAction *)rotateToAngle:(CGFloat)radians duration:(NSTimeInterval)sec shortestUnitArc:(BOOL)shortestUnitArc
Parameters
radians

The angle to rotate the node to, in radians.

sec

The duration of the animation.

shortestUnitArc

If YES, then the rotation is performed in whichever direction results in the smallest rotation. If NO, then the rotation is interpolated.

Return Value

A new action object.

Discussion

When the action executes, the node’s zRotation property is animated to the new angle.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

runAction:onChildWithName:

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

+ (SKAction *)runAction:(SKAction *)action onChildWithName:(NSString *)name
Parameters
action

The action to execute.

name

The name of a child object. See the name property on the SKNode object.

Return Value

A new action object.

Discussion

This action has an instantaneous duration, although the action executed on the child may have a duration of its own. When the action executes, it looks up an appropriate child node and calls its runAction: method, passing in the action to execute.

This action is reversible; it tells the child to execute the reverse of the action specified by the action parameter.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

runBlock:

Creates an action that executes a block.

+ (SKAction *)runBlock:(dispatch_block_t)block
Parameters
block

The block to run.

Return Value

A new action object.

Discussion

When the action executes, the block is called. This action takes place instantaneously.

This action is not reversible; the reverse action executes the same block.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

runBlock:queue:

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

+ (SKAction *)runBlock:(dispatch_block_t)block queue:(dispatch_queue_t)queue
Parameters
block

The block to run.

queue

The queue to perform the action on.

Return Value

A new action object.

Discussion

When the action executes, the block is called. This action takes place instantaneously.

This action is not reversible; the reverse action executes the same block.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

scaleBy:duration:

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

+ (SKAction *)scaleBy:(CGFloat)scale duration:(NSTimeInterval)sec
Parameters
scale

The amount to add to the node’s x and y scale values.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s xScale and yScale properties are animated to the new value.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction scaleBy: -scale duration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

scaleTo:duration:

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

+ (SKAction *)scaleTo:(CGFloat)scale duration:(NSTimeInterval)sec
Parameters
scale

The new value for the node’s x and y scale values.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s xScale and yScale properties are animated to the new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

scaleXBy:y:duration:

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

+ (SKAction *)scaleXBy:(CGFloat)xScale y:(CGFloat)yScale duration:(NSTimeInterval)sec
Parameters
xScale

The amount to add to the node’s x scale value.

yScale

The amount to add to the node’s y scale value.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s xScale and yScale properties are animated to the new value.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction scaleXBy: -xScale y: -yScale duration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

scaleXTo:duration:

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

+ (SKAction *)scaleXTo:(CGFloat)scale duration:(NSTimeInterval)sec
Parameters
scale

The new value for the node’s x scale value.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s xScale property animates to the new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

scaleXTo:y:duration:

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

+ (SKAction *)scaleXTo:(CGFloat)xScale y:(CGFloat)yScale duration:(NSTimeInterval)sec
Parameters
xScale

The new value for the node’s x scale value.

yScale

The new value for the node’s y scale value.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s xScale and yScale properties are animated to the new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

scaleYTo:duration:

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

+ (SKAction *)scaleYTo:(CGFloat)scale duration:(NSTimeInterval)sec
Parameters
scale

The new value for the node’s y scale value.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s yScale property animates to the new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

sequence:

Creates an action that runs a collection of actions sequentially.

+ (SKAction *)sequence:(NSArray *)actions
Parameters
actions

An array of SKAction objects.

Return Value

A sequence action object.

Discussion

When the action executes, the first action in the sequence starts and runs to completion. Subsequent actions in the sequence run in a similar fashion until all of the actions in the sequence have executed. The duration of the sequence action is the sum of the durations of the actions in the sequence.

This action is reversible; it creates a new sequence action that reverses the order of the actions. Each action in the reversed sequence is itself reversed. For example, if an action sequence is {1,2,3}, the reversed sequence would be {3R,2R,1R}.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

setTexture:

Creates an action that changes a sprite’s texture.

+ (SKAction *)setTexture:(SKTexture *)texture
Parameters
texture

The new texture to use on the sprite.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s texture property changes immediately to the new texture.

This action is not reversible; the reverse of this action does nothing.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

setTexture:resize:

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

+ (SKAction *)setTexture:(SKTexture *)texture resize:(BOOL)resize
Parameters
texture

The new texture to use on the sprite.

resize

If YES, the sprite is resized to match the new texture. If NO, the size of the sprite is unchanged.

Return Value

A new action object.

Discussion

This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s texture property changes immediately to the new texture and the sprite is resized to match.

This action is not reversible; the reverse of this action does nothing.

Availability
  • Available in iOS 7.1 and later.
Declared In
SKAction.h

speedBy:duration:

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

+ (SKAction *)speedBy:(CGFloat)speed duration:(NSTimeInterval)sec
Parameters
speed

The amount to add to the node’s speed.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s speed property animates to the new value.

This action is reversible; the reverse is created as if the following code were executed:

[SKAction speedBy: -speed duration: sec];
Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

speedTo:duration:

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

+ (SKAction *)speedTo:(CGFloat)speed duration:(NSTimeInterval)sec
Parameters
speed

The new value for the node’s speed.

sec

The duration of the animation.

Return Value

A new action object.

Discussion

When the action executes, the node’s speed property animates to the new value.

This action is not reversible; the reverse of this action has the same duration, but does not change anything.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

waitForDuration:

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

+ (SKAction *)waitForDuration:(NSTimeInterval)sec
Parameters
sec

The amount of time to wait.

Return Value

A new action object.

Discussion

When the action executes, the action waits for the specified amount of time, then ends. This is typically used as part of a sequence of actions to insert a delay between two other actions. You might also use it in conjunction with the runAction:completion: method to trigger code that needs to run at a later time.

This action is not reversible; the reverse of this action is the same action.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

waitForDuration:withRange:

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

+ (SKAction *)waitForDuration:(NSTimeInterval)sec withRange:(NSTimeInterval)durationRange
Parameters
sec

The average amount of time to wait.

durationRange

The range of possible values for the duration.

Return Value

A new action object.

Discussion

When the action executes, the action waits for the specified amount of time, then ends. This is typically used as part of a sequence of actions to insert a delay between two other actions. However, you might also use it in conjunction with the runAction:completion: method to trigger code that needs to run at a later time.

Each time the action is executed, the action computes a new random value for the duration. The duration may vary in either direction by up to half of the value of the durationRange parameter.

This action is not reversible; the reverse of this action is the same action.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

Instance Methods

reversedAction

Creates an action that reverses the behavior of another action.

- (SKAction *)reversedAction
Return Value

A new action that reverses an action’s behavior.

Discussion

This method always returns an action object; however, not all actions are reversible. When reversed, some actions return an object that either does nothing or that performs the same action as the original action. For details on how an action is reversed, see the description of the class method used to create that action.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKAction.h

Constants

Action Timing Modes

The modes that an action can use to adjust the apparent timing of the action.

typedef SKActionTimingMode : NSInteger {
   SKActionTimingLinear,
   SKActionTimingEaseIn,
   SKActionTimingEaseOut,
   SKActionTimingEaseInEaseOut,
} SKActionTimingMode;
Constants
SKActionTimingLinear

Specifies linear pacing. Linear pacing causes an animation to occur evenly over its duration.

Available in iOS 7.0 and later.

Declared in SKAction.h.

SKActionTimingEaseIn

Specifies ease-in pacing. Ease-in pacing causes the animation to begin slowly, and then speed up as it progresses.

Available in iOS 7.0 and later.

Declared in SKAction.h.

SKActionTimingEaseOut

Specifies ease-out pacing. Ease-out pacing causes the animation to begin quickly, and then slow as it completes.

Available in iOS 7.0 and later.

Declared in SKAction.h.

SKActionTimingEaseInEaseOut

Specifies ease-in ease-out pacing. An ease-in ease-out animation begins slowly, accelerates through the middle of its duration, and then slows again before completing.

Available in iOS 7.0 and later.

Declared in SKAction.h.