iOS Developer Library — Prerelease

Developer

SpriteKit Framework Reference SKAction Class Reference

Options
Deployment Target:

On This Page
Language:

SKAction

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:

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

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.

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

    Declaration

    Swift

    class func moveByX(_ deltaX: CGFloat, y deltaY: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction moveByX: -deltaX y: -deltaY duration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func moveBy(_ delta: CGVector, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. CGVector negDelta = CGVectorMake(-delta.dx,-delta.dy);
    2. [SKAction moveBy: negDelta duration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func moveTo(_ location: CGPoint, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

  • Creates an action that moves a node horizontally.

    Declaration

    Swift

    class func moveToX(_ x: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

  • Creates an action that moves a node vertically.

    Declaration

    Swift

    class func moveToY(_ y: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func followPath(_ path: CGPath, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)followPath:(CGPathRef nonnull)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 YEStrue 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.

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

    Declaration

    Swift

    class func followPath(_ path: CGPath, speed speed: CGFloat) -> SKAction

    Objective-C

    + (SKAction * nonnull)followPath:(CGPathRef nonnull)path speed:(CGFloat)speed

    Parameters

    path

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

    speed

    The speed at which the node should move, in points per second.

    Return Value

    A new action object.

    Discussion

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

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

    Availability

    Available in iOS 8.0 and later.

  • Creates an action that moves the node along a path.

    Declaration

    Swift

    class func followPath(_ path: CGPath, asOffset offset: Bool, orientToPath orient: Bool, duration sec: NSTimeInterval) -> SKAction

    Objective-C

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

    Parameters

    path

    A path to follow.

    offset

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

    orient

    If YEStrue, the node’s zRotation property animates so that the node turns to follow the path. If NOfalse, 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.

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

    Declaration

    Swift

    class func followPath(_ path: CGPath, asOffset offset: Bool, orientToPath orient: Bool, speed speed: CGFloat) -> SKAction

    Objective-C

    + (SKAction * nonnull)followPath:(CGPathRef nonnull)path asOffset:(BOOL)offset orientToPath:(BOOL)orient speed:(CGFloat)speed

    Parameters

    path

    A path to follow.

    offset

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

    orient

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

    speed

    The speed at which the node should move, in points per second.

    Return Value

    A new action object.

    Discussion

    When the action executes, the node’s position and zRotation properties are animated along the provided path. The duration of the action is determined by the length of the path and the speed of the node.

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

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    class func rotateByAngle(_ radians: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction rotateByAngle: -radians duration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func rotateToAngle(_ radians: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func rotateToAngle(_ radians: CGFloat, duration sec: NSTimeInterval, shortestUnitArc shortestUnitArc: Bool) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 YEStrue, the rotation is performed in whichever direction results in the smallest rotation. If NOfalse, 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.

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

    Declaration

    Swift

    class func speedBy(_ speed: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction speedBy: -speed duration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func speedTo(_ speed: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func scaleBy(_ scale: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction scaleBy: -scale duration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func scaleTo(_ scale: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func scaleXBy(_ xScale: CGFloat, y yScale: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction scaleXBy: -xScale y: -yScale duration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func scaleXTo(_ xScale: CGFloat, y yScale: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func scaleXTo(_ scale: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func scaleYTo(_ scale: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

  • Creates an action that makes a node visible.

    Declaration

    Swift

    class func unhide() -> SKAction

    Objective-C

    + (SKAction * nonnull)unhide

    Return Value

    A new action object.

    Discussion

    This action has an instantaneous duration. When the action executes, the node’s hidden property is set to NOfalse.

    This action is reversible; the reversed action hides the node.

    Availability

    Available in iOS 8.0 and later.

  • Creates an action that hides a node.

    Declaration

    Swift

    class func hide() -> SKAction

    Objective-C

    + (SKAction * nonnull)hide

    Return Value

    A new action object.

    Discussion

    This action has an instantaneous duration. When the action executes, the node’s hidden property is set to YEStrue.

    This action is reversible; the reversed action shows the node.

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    class func fadeInWithDuration(_ sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction fadeOutWithDuration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func fadeOutWithDuration(_ sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction fadeInWithDuration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func fadeAlphaBy(_ factor: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction fadeAlphaBy: -factor duration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func fadeAlphaTo(_ alpha: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

  • Creates an action that adjusts the size of a sprite.

    Declaration

    Swift

    class func resizeByWidth(_ width: CGFloat, height height: CGFloat, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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 is executed:

    1. [SKAction resizeByWidth: -width height: -height duration: sec];

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func resizeToHeight(_ height: CGFloat, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func resizeToWidth(_ width: CGFloat, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func resizeToWidth(_ width: CGFloat, height height: CGFloat, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func setTexture(_ texture: SKTexture) -> SKAction

    Objective-C

    + (SKAction * nonnull)setTexture:(SKTexture * nonnull)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 9.0 and later.

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

    Declaration

    Swift

    class func setTexture(_ texture: SKTexture, resize resize: Bool) -> SKAction

    Objective-C

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

    Parameters

    texture

    The new texture to use on the sprite.

    resize

    If YEStrue, the sprite is resized to match the new texture. Otherwise, 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.

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

    Declaration

    Swift

    class func animateWithTextures(_ textures: [SKTexture], timePerFrame sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)animateWithTextures:(NSArray<SKTexture *> * nonnull)textures timePerFrame:(NSTimeInterval)sec

    Parameters

    textures

    An array of textures to use when animating a sprite.

    sec

    The duration, in seconds, 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.

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

    Declaration

    Swift

    class func animateWithTextures(_ textures: [SKTexture], timePerFrame sec: NSTimeInterval, resize resize: Bool, restore restore: Bool) -> SKAction

    Objective-C

    + (SKAction * nonnull)animateWithTextures:(NSArray<SKTexture *> * nonnull)textures timePerFrame:(NSTimeInterval)sec resize:(BOOL)resize restore:(BOOL)restore

    Parameters

    textures

    An array of textures to use when animating a sprite.

    sec

    The amount of time, in seconds, that each texture is displayed.

    resize

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

    restore
    • If YEStrue:

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

    • If NOfalse:

      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.

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

    Declaration

    Swift

    class func setNormalTexture(_ texture: SKTexture) -> SKAction

    Objective-C

    + (SKAction * nonnull)setNormalTexture:(SKTexture * nonnull)texture

    Parameters

    texture

    The new texture to use on the sprite.

    Return Value

    An action that changes a sprite’s normal texture.

    Discussion

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

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

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func setNormalTexture(_ texture: SKTexture, resize resize: Bool) -> SKAction

    Objective-C

    + (SKAction * nonnull)setNormalTexture:(SKTexture * nonnull)texture resize:(BOOL)resize

    Parameters

    texture

    The new texture to use on the sprite.

    resize

    If YEStrue, the sprite is resized to match the new texture. Otherwise, the size of the sprite is unchanged.

    Return Value

    An action that changes a sprite’s normal texture.

    Discussion

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

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func animateWithNormalTextures(_ textures: [SKTexture], timePerFrame sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)animateWithNormalTextures:(NSArray<SKTexture *> * nonnull)textures timePerFrame:(NSTimeInterval)sec

    Parameters

    textures

    An array of textures to use.

    sec

    The amount of time that each texture is displayed.

    Return Value

    A new action to change a sprite’s normal texture.

    Discussion

    This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s normalTexture property animates through the array of textures. The sprite’s normalTexture 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 9.0 and later.

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

    Declaration

    Swift

    class func animateWithNormalTextures(_ textures: [SKTexture], timePerFrame sec: NSTimeInterval, resize resize: Bool, restore restore: Bool) -> SKAction

    Objective-C

    + (SKAction * nonnull)animateWithNormalTextures:(NSArray<SKTexture *> * nonnull)textures timePerFrame:(NSTimeInterval)sec resize:(BOOL)resize restore:(BOOL)restore

    Parameters

    textures

    An array of textures to use when animating a sprite.

    sec

    The amount of time that each texture is displayed.

    resize

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

    restore
    • If YEStrue:

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

    • If NOfalse:

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

    Return Value

    A new action to change a sprite’s texture.

    Discussion

    This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s normalTexture property animates through the array of textures. The sprite’s normalTexture 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 9.0 and later.

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

    Declaration

    Swift

    class func colorizeWithColor(_ color: UIColor, colorBlendFactor colorBlendFactor: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)colorizeWithColor:(UIColor * nonnull)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.

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

    Declaration

    Swift

    class func colorizeWithColorBlendFactor(_ colorBlendFactor: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func applyForce(_ force: CGVector, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)applyForce:(CGVector)force duration:(NSTimeInterval)sec

    Parameters

    force

    A vector that describes how much force is applied in each dimension. The force is measured in Newtons.

    sec

    The duration over which the force is applied to the physics body.

    Return Value

    A new action object.

    Discussion

    When the action executes, the force is applied continuously to the physics body for the duration of the action. This action accelerates the body without imparting any angular acceleration to it.

    This action is reversible; it applies an equal force in the opposite direction.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func applyTorque(_ torque: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)applyTorque:(CGFloat)torque duration:(NSTimeInterval)sec

    Parameters

    torque

    The amount of torque, in Newton-meters.

    sec

    The duration over which the torque is applied to the physics body.

    Return Value

    A new action object.

    Discussion

    When the action executes, the torque is applied continuously to the physics body for the duration of the action. This action generates an angular acceleration on the body without causing any linear acceleration.

    This action is reversible; it applies an equal torque in the opposite direction.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func applyForce(_ force: CGVector, atPoint point: CGPoint, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)applyForce:(CGVector)force atPoint:(CGPoint)point duration:(NSTimeInterval)sec

    Parameters

    force

    A vector that describes how much force is applied in each dimension. The force is measured in Newtons.

    point

    A point in scene coordinates that defines where the force is applied to the physics body.

    sec

    The duration over which the force is applied to the physics body.

    Return Value

    A new action object.

    Discussion

    When the action executes, the force is applied continuously to the physics body for the duration of the action. Because the force is applied to a specific point on the body, it may impart both linear acceleration and angular acceleration.

    This action is reversible; it applies an equal force in the opposite direction.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func applyImpulse(_ impulse: CGVector, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)applyImpulse:(CGVector)impulse duration:(NSTimeInterval)sec

    Parameters

    impulse

    A vector that describes how much momentum to impart to the body in each dimension over the duration of the action. The impulse is measured in Newton-seconds.

    sec

    The duration over which the total impulse should be applied to the physics body.

    Return Value

    A new action object.

    Discussion

    When the action executes, applies a constant force to the physics body for the duration of the action. The force is calculated by dividing the impulse strength by the duration of the action. For example, if an impulse of 1 Newton-second is applied to the physics body, and the the duration is 10 seconds, then a force of 0.1 Newtons is applied to the physics body.

    This action is reversible; it applies an equal impulse in the opposite direction.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func applyAngularImpulse(_ impulse: CGFloat, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)applyAngularImpulse:(CGFloat)impulse duration:(NSTimeInterval)sec

    Parameters

    impulse

    The total impulse to apply to the physics body. The impulse is measured in Newton-seconds.

    sec

    The number of seconds over which to apply the impulse. For example, if you specify a duration of four seconds, one quarter of the impulse will be applied each second.

    Return Value

    A new action object.

    Discussion

    When the action executes, applies a constant torque to the physics body for the duration of the action. The torque is calculated by dividing the impulse strength by the duration of the action. This action affects the body’s angular velocity without changing the body’s linear velocity.

    This action is reversible; it applies an equal angular impulse in the opposite direction.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func applyImpulse(_ impulse: CGVector, atPoint point: CGPoint, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)applyImpulse:(CGVector)impulse atPoint:(CGPoint)point duration:(NSTimeInterval)sec

    Parameters

    impulse

    The total impulse to apply to the physics body. The impulse is measured in Newton-seconds.

    point

    A point in scene coordinates that defines where the impulse was applied to the physics body.

    sec

    A new action object.

    Return Value

    A new action object.

    Discussion

    When the action executes, applies a constant force to the physics body for the duration of the action. The force is calculated by dividing the impulse strength by the duration of the action. For example, if an impulse of 1 Newton-second is applied to the physics body, and the the duration is 10 seconds, then a force of 0.1 Newtons is applied to the physics body. Because the force is applied to a specific point on the body, it may impart both linear acceleration and angular acceleration.

    This action is reversible; it applies an equal impulse in the opposite direction.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeChargeTo(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeChargeTo:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The new charge of the physics body.

    duration

    The duration of the animation.

    Return Value

    A new action object.

    Discussion

    When the action executes, the physics body’s charge property animates from its current value to its new value.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeChargeBy(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeChargeBy:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The amount to add to the physics body’s charge.

    duration

    The duration of the animation.

    Return Value

    A new action object.

    Discussion

    When the action executes, the physics body’s charge property animates from its current value to its new value.

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

    1. [SKAction changeChargeBy: -v duration: sec];

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeMassTo(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeMassTo:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The new mass of the physics body.

    duration

    The duration of the animation.

    Return Value

    A new action object.

    Discussion

    When the action executes, the physics body’s mass property animates from its current value to its new value.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeMassBy(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeMassBy:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The amount to add to the physics body’s mass.

    duration

    The duration of the animation.

    Return Value

    A new action object.

    Discussion

    When the action executes, the physics body’s mass property animates from its current value to its new value.

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

    1. [SKAction changeMassBy: -v duration: sec];

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func strengthTo(_ strength: Float, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)strengthTo:(float)strength duration:(NSTimeInterval)sec

    Parameters

    strength

    The new strength for the field.

    sec

    The duration of the animation.

    Return Value

    A new action object.

    Discussion

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

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

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    class func strengthBy(_ strength: Float, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)strengthBy:(float)strength duration:(NSTimeInterval)sec

    Parameters

    strength

    The value to add to the field.

    sec

    The duration of the animation.

    Return Value

    A new action object.

    Discussion

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

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

    1. [SKAction strengthBy: -strength duration: sec];

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    class func falloffTo(_ falloff: Float, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)falloffTo:(float)falloff duration:(NSTimeInterval)sec

    Parameters

    falloff

    The new falloff for the field.

    sec

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action runs, the field node’s falloff property animates from its current value to its new value. This action is not reversible.

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    class func falloffBy(_ falloff: Float, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)falloffBy:(float)falloff duration:(NSTimeInterval)sec

    Parameters

    falloff

    The value to add to the falloff.

    sec

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

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

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

    1. [SKAction falloffBy: -falloff duration: sec];

    Availability

    Available in iOS 8.0 and later.

  • Creates an action that plays a sound.

    Declaration

    Swift

    class func playSoundFileNamed(_ soundFile: String, waitForCompletion wait: Bool) -> SKAction

    Objective-C

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

    Parameters

    soundFile

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

    wait

    If YEStrue, the duration of this action is the same as the length of the audio playback. If NOfalse, the action is considered to have completed immediately.

    Return Value

    A new action object.

    Discussion

    Use SKAction playSoundFileNamed:waitForCompletion: only for short incidentals. Use AVAudioPlayer for long running background music. This action is not reversible; the reversed action is identical to the original action.

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func play() -> SKAction

    Objective-C

    + (SKAction * nonnull)play

    Return Value

    A new action object.

    Discussion

    This action may only be executed on an SKAudioNode object.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func pause() -> SKAction

    Objective-C

    + (SKAction * nonnull)pause

    Return Value

    A new action object.

    Discussion

    This action may only be executed on an SKAudioNode object. The audio is paused, and if restarted, resumes at where it was paused.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func stop() -> SKAction

    Objective-C

    + (SKAction * nonnull)stop

    Return Value

    A new action object.

    Discussion

    This action may only be executed on an SKAudioNode object. The audio is stopped, and if restarted, begins at the beginning.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changePlaybackRateTo(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changePlaybackRateTo:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The new value for the playback rate. A playback rate of 1.0 represents normal speed.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s playback rate animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changePlaybackRateBy(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changePlaybackRateBy:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The amount to change the playback rate by. A playback rate of 1.0 represents normal speed.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s playback rate animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

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

    1. [SKAction changePlaybackRateBy: -v duration: sec];

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeVolumeTo(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeVolumeTo:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The new value for the volume. The value should be between 0.0 (silence) and 1.0 (maximum value for source audio), inclusive.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s volume animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeVolumeBy(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeVolumeBy:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The amount to change the volume by.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s volume animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

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

    1. [SKAction changeVolumeBy: -v duration: sec];

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeObstructionTo(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeObstructionTo:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The new value for the obstruction, in decibels.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s obstruction animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeObstructionBy(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeObstructionBy:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The amount to change the obstruction by, in decibels.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s obstruction animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

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

    1. [SKAction changeObstructionBy: -v duration: sec];

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeOcclusionTo(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeOcclusionTo:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The new value for the occlusion, in decibels.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s occlusion animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeOcclusionBy(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeOcclusionBy:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The amount to change the occlusion by, in decibels.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s occlusion animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

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

    1. [SKAction changeOcclusionBy: -v duration: sec];

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeReverbTo(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeReverbTo:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The new value for the reverb. The value should be between 0.0 and 1.0, inclusive.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s reverb animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func changeReverbBy(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)changeReverbBy:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The amount to change the reverb by.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s reverb animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

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

    1. [SKAction changeReverbBy: -v duration: sec];

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func stereoPanTo(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)stereoPanTo:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The new value for stereo panning. The value must between -1.0 (left channel only) and 1.0 (right channel only), inclusive.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s stereo panning animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

    This action is not reversible.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    class func stereoPanBy(_ v: Float, duration duration: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)stereoPanBy:(float)v duration:(NSTimeInterval)duration

    Parameters

    v

    The amount to change the stereo panning by.

    duration

    The duration of the animation, in seconds.

    Return Value

    A new action object.

    Discussion

    When the action executes, the audio node’s stereo panning animates from its current value to its new value. For more information, see AVAudio3DMixing Protocol Reference.

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

    1. [SKAction changeStereoPanBy: -v duration: sec];

    Availability

    Available in iOS 9.0 and later.

  • Creates an action that removes the node from its parent.

    Declaration

    Swift

    class func removeFromParent() -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func runAction(_ action: SKAction, onChildWithName name: String) -> SKAction

    Objective-C

    + (SKAction * nonnull)runAction:(SKAction * nonnull)action onChildWithName:(NSString * nonnull)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.

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

    Declaration

    Swift

    class func group(_ actions: [SKAction]) -> SKAction

    Objective-C

    + (SKAction * nonnull)group:(NSArray<SKAction *> * nonnull)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.

  • Creates an action that runs a collection of actions sequentially.

    Declaration

    Swift

    class func sequence(_ actions: [SKAction]) -> SKAction

    Objective-C

    + (SKAction * nonnull)sequence:(NSArray<SKAction *> * nonnull)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.

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

    Declaration

    Swift

    class func repeatAction(_ action: SKAction, count count: Int) -> SKAction

    Objective-C

    + (SKAction * nonnull)repeatAction:(SKAction * nonnull)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.

  • Creates an action that repeats another action forever.

    Declaration

    Swift

    class func repeatActionForever(_ action: SKAction) -> SKAction

    Objective-C

    + (SKAction * nonnull)repeatActionForever:(SKAction * nonnull)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.

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

    Declaration

    Swift

    class func waitForDuration(_ sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

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

    Declaration

    Swift

    class func waitForDuration(_ sec: NSTimeInterval, withRange durationRange: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)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.

  • Creates an action that rotates a series of nodes, starting with the node this action is executed on, so that this node position moves closer to the specified point.

    Declaration

    Swift

    class func reachTo(_ position: CGPoint, rootNode root: SKNode, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)reachTo:(CGPoint)position rootNode:(SKNode * nonnull)root duration:(NSTimeInterval)sec

    Parameters

    position

    The intended destination for the node, specified in the scene’s coordinate system.

    root

    The highest level ancestor of the target node that should be rotated.

    sec

    The length of the animation.

    Return Value

    A new action object.

    Discussion

    This action is typically used to implement character animation across a series of moving parts. When the action executes, it performs an inverse kinematic calculation to determine new rotation values for the target node and any of its ancestors up to and including the root node. Each node is rotated around its anchor point in an attempt to get the targeted node’s position closer to the intended destination. Each node’s rotation value is constrained by that node’s reachConstraints property. If the action cannot successfully reach the target position, it gets the node as close as it can to the target position.

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

    Availability

    Available in iOS 8.0 and later.

  • Creates an action that rotates a series of nodes, starting with the node this action is executed on, so that this node position moves closer to another node’s position. The duration of the animation is determined by specifying the speed of the targeted node.

    Declaration

    Swift

    class func reachTo(_ position: CGPoint, rootNode root: SKNode, velocity velocity: CGFloat) -> SKAction

    Objective-C

    + (SKAction * nonnull)reachTo:(CGPoint)position rootNode:(SKNode * nonnull)root velocity:(CGFloat)velocity

    Parameters

    position

    The intended destination for the node, specified in the scene’s coordinate system.

    root

    The highest level ancestor of the target node that should be rotated.

    velocity

    The maximum speed at which the node should move.

    Return Value

    A new action object.

    Discussion

    This action is typically used to implement character animation across a series of moving parts. When the action executes, it performs an inverse kinematic calculation to determine new rotation values for the target node and any of its ancestors up to and including the root node. Each node is rotated around its anchor point in an attempt to get the targeted node’s position closer to the intended destination. Each node’s rotation value is constrained by that node’s reachConstraints property. If the action cannot successfully reach the target position, it gets the node as close as it can to the target position.

    The duration of the action is calculated implicitly based on the speed of movement and the distance that the node needs to travel.

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

    Availability

    Available in iOS 8.0 and later.

  • Creates an action that rotates a series of nodes, starting with the node this action is executed on, so that this node position moves closer to another node’s position.

    Declaration

    Swift

    class func reachToNode(_ node: SKNode, rootNode root: SKNode, duration sec: NSTimeInterval) -> SKAction

    Objective-C

    + (SKAction * nonnull)reachToNode:(SKNode * nonnull)node rootNode:(SKNode * nonnull)root duration:(NSTimeInterval)sec

    Parameters

    node

    The node whose position the current node should move closer to.

    root

    The highest level ancestor of the target node that should be rotated.

    sec

    The length of the animation.

    Return Value

    A new action object.

    Discussion

    This action is typically used to implement character animation across a series of moving parts. When the action executes, it performs an inverse kinematic calculation to determine new rotation values for the target node and any of its ancestors up to and including the root node. Each node is rotated around its anchor point in an attempt to get the targeted node’s position closer to the intended destination. Each node’s rotation value is constrained by that node’s reachConstraints property. If the action cannot successfully reach the target position, it gets the node as close as it can to the target position.

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

    Availability

    Available in iOS 8.0 and later.

  • Creates an action that rotates a series of nodes, starting at the current node, so that the target node reaches the position of another node.

    Declaration

    Swift

    class func reachToNode(_ node: SKNode, rootNode root: SKNode, velocity velocity: CGFloat) -> SKAction

    Objective-C

    + (SKAction * nonnull)reachToNode:(SKNode * nonnull)node rootNode:(SKNode * nonnull)root velocity:(CGFloat)velocity

    Parameters

    node

    The node whose position the current node should move closer to.

    root

    The highest level ancestor of the target node that should be rotated.

    velocity

    The speed that the current node should move at.

    Return Value

    A new action object.

    Discussion

    This action is typically used to implement character animation across a series of moving parts. When the action executes, it performs an inverse kinematic calculation to determine new rotation values for the target node and any of its ancestors up to and including the root node. Each node is rotated around its anchor point in an attempt to get the targeted node’s position closer to the intended destination. Each node’s rotation value is constrained by that node’s reachConstraints property. If the action cannot successfully reach the target position, it gets the node as close as it can to the target position.

    The duration of the action is calculated implicitly based on the speed of movement and the distance that the node needs to travel.

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

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    init?(named name: String)

    Objective-C

    + (SKAction * nullable)actionNamed:(NSString * nonnull)name

    Parameters

    name

    The name of the action.

    Return Value

    A new action object.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    init?(named name: String, duration sec: NSTimeInterval)

    Objective-C

    + (SKAction * nullable)actionNamed:(NSString * nonnull)name duration:(NSTimeInterval)sec

    Parameters

    name

    The name of the action.

    sec

    The duration of the action.

    Return Value

    A new action object.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    init?(named name: String, fromURL url: NSURL)

    Objective-C

    + (SKAction * nullable)actionNamed:(NSString * nonnull)name fromURL:(NSURL * nonnull)url

    Parameters

    name

    The name of the action.

    url

    The URL of the file containing the action.

    Return Value

    A new action object.

    Availability

    Available in iOS 9.0 and later.

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

    Declaration

    Swift

    init?(named name: String, fromURL url: NSURL, duration sec: NSTimeInterval)

    Objective-C

    + (SKAction * nullable)actionNamed:(NSString * nonnull)name fromURL:(NSURL * nonnull)url duration:(NSTimeInterval)sec

    Parameters

    name

    The name of the action.

    url

    The URL of the file containing the action.

    sec

    The duration of the action, in seconds.

    Return Value

    A new action object.

    Availability

    Available in iOS 9.0 and later.

  • Creates an action that executes a block over a duration.

    Declaration

    Swift

    class func customActionWithDuration(_ seconds: NSTimeInterval, actionBlock block: (SKNode, CGFloat) -> Void) -> SKAction

    Objective-C

    + (SKAction * nonnull)customActionWithDuration:(NSTimeInterval)seconds actionBlock:(void (^ nonnull)(SKNode * nonnull 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.

  • Creates an action that calls a method on an object.

    Declaration

    Objective-C

    + (SKAction * nonnull)performSelector:(SEL nonnull)selector onTarget:(id nonnull)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.

  • Creates an action that executes a block.

    Declaration

    Swift

    class func runBlock(_ block: dispatch_block_t) -> SKAction

    Objective-C

    + (SKAction * nonnull)runBlock:(dispatch_block_t nonnull)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.

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

    Declaration

    Swift

    class func runBlock(_ block: dispatch_block_t, queue queue: dispatch_queue_t) -> SKAction

    Objective-C

    + (SKAction * nonnull)runBlock:(dispatch_block_t nonnull)block queue:(dispatch_queue_t nonnull)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.

  • Creates an action that reverses the behavior of another action.

    Declaration

    Swift

    func reversedAction() -> SKAction

    Objective-C

    - (SKAction * nonnull)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.

  • A speed factor that modifies how fast an action runs.

    Declaration

    Swift

    var speed: CGFloat

    Objective-C

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

  • The timing mode used to execute an action.

    Declaration

    Swift

    var timingMode: SKActionTimingMode

    Objective-C

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

    See Also

    timingFunction

  • A block used to customize the timing function.

    Declaration

    Swift

    var timingFunction: SKActionTimingFunction

    Objective-C

    @property(nonatomic) SKActionTimingFunction timingFunction

    Discussion

    If a timing function is provided, after the normal timing mode is applied, the result is sent to the timing function. The return SKActionTimingFunction value of the timing function determines the actual time used to perform the animation.

    Availability

    Available in iOS 8.0 and later.

    See Also

    timingMode

  • The duration required to complete an action.

    Declaration

    Swift

    var duration: NSTimeInterval

    Objective-C

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

Data Types

  • The signature for the custom timing block.

    Declaration

    Swift

    typealias SKActionTimingFunction = (Float) -> Float

    Objective-C

    typedef float (^SKActionTimingFunction)(float time);

    Discussion

    The block parameters are defined as follows:

    time

    The input time, where 0.0 represents the start time of the animation and 1.0 represents the end time of the animation.

    The input value will be a value between 0.0 and 1.0, inclusive. The block must also return a value between 0.0 and 1.0. When the input time is 0.0, the output value should be 0.0. When the input time is 1.0, the output value should also be 1.0.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    enum SKActionTimingMode : Int { case Linear case EaseIn case EaseOut case EaseInEaseOut }

    Objective-C

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

    Constants

    • Linear

      SKActionTimingLinear

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

      Available in iOS 7.0 and later.

    • EaseIn

      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.

    • EaseOut

      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.

    • EaseInEaseOut

      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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.