iOS Developer Library

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.

Inheritance


Conforms To


Import Statement


Swift

import SpriteKit

Objective-C

@import SpriteKit;

Availability


Available in iOS 7.0 and later.
  • 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 *)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:

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

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

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

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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 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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)followPath:(CGPathRef)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)followPath:(CGPathRef)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)followPath:(CGPathRef)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

    • [SKAction rotateByAngle: -radians duration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

    • [SKAction speedBy: -speed duration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

    • [SKAction scaleBy: -scale duration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

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

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • Creates an action that hides a node.

    Declaration

    Swift

    class func hide() -> SKAction

    Objective-C

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

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

    • [SKAction fadeOutWithDuration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

    • [SKAction fadeInWithDuration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

    • [SKAction fadeAlphaBy: -factor duration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

    • [SKAction resizeByWidth: -width height: -height duration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.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 *)setTexture:(SKTexture *)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. If NOfalse, 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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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: [AnyObject], timePerFrame sec: NSTimeInterval) -> SKAction

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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: [AnyObject], timePerFrame sec: NSTimeInterval, resize resize: Bool, restore restore: Bool) -> SKAction

    Objective-C

    + (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 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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.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 *)colorizeWithColor:(UIColor *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

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

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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:

    • [SKAction strengthBy: -strength duration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)falloffTo:(float)falloff duration:(NSTimeInterval)sec

    Parameters

    falloff

    The new falloff for the field.

    sec

    The duration of the animation.

    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 not reversible; the reverse of this action has the same duration but does not do anything.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)falloffBy:(float)falloff duration:(NSTimeInterval)sec

    Parameters

    falloff

    The value to add to the falloff.

    sec

    The duration of the animation.

    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:

    • [SKAction falloffBy: -falloff duration: sec];

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)playSoundFileNamed:(NSString *)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

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

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    class func removeFromParent() -> SKAction

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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: [AnyObject]) -> SKAction!

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

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

    Objective-C

    + (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}.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)reachTo:(CGPoint)position rootNode:(SKNode *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)reachTo:(CGPoint)position rootNode:(SKNode *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)reachToNode:(SKNode *)node rootNode:(SKNode *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)reachToNode:(SKNode *)node rootNode:(SKNode *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • Creates an action that executes a block.

    Declaration

    Swift

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

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import SpriteKit;

    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 *)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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • speed speed Property

    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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    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 value of the timing function determines the actual time used to perform the animation.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

    See Also

    timingMode

  • duration duration Property

    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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

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