Class

SKAction

An object which is executed by an SKNode to change its structure or content.

Overview

An SKAction object is an action that is executed by a node in the scene (SKScene). Actions are most often used to change the structure and content of the node to which they are attached but can also make other changes to the scene. When the scene processes its nodes, actions associated with those nodes are evaluated.To create an action, call the class method for the action you are interested in. Then, configure the action’s properties. Finally, to execute the action, call a node object’s run(_:) method (or a similar method on the SKNode class) and pass it the action object.

Most actions allow you to change a node’s properties, such as its position, rotation, or scale. Some actions specifically apply only to SKSpriteNode objects, allowing you to animate a sprite’s color or texture properties. Many of these actions are animated by Sprite Kit, meaning that they change the properties of the associated node over more than one frame of animation rendered by the scene. When an action is animated, the duration property states how long that action takes to complete in seconds and its timingMode property defines the rate at which the animation executes. The action’s speed property allows you to adjust the timing of the animation by increasing or decreasing its playback speed.

Many actions can be reversed, allowing you to create another action object that reverses the effect of that action. For example, if an action object moves a node 20 points to the right of its current position, the reversed action moves the node 20 points to the left. To create a reversed action object, call an action object’s reversed() 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.

Symbols

Creating Actions That Move Nodes

class func moveBy(x: CGFloat, y: CGFloat, duration: TimeInterval)

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

class func move(by: CGVector, duration: TimeInterval)

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

class func move(to: CGPoint, duration: TimeInterval)

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

class func moveTo(x: CGFloat, duration: TimeInterval)

Creates an action that moves a node horizontally.

class func moveTo(y: CGFloat, duration: TimeInterval)

Creates an action that moves a node vertically.

class func follow(CGPath, duration: TimeInterval)

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

class func follow(CGPath, speed: CGFloat)

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

class func follow(CGPath, asOffset: Bool, orientToPath: Bool, speed: CGFloat)

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

Creating Actions That Rotate Nodes

class func rotate(byAngle: CGFloat, duration: TimeInterval)

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

class func rotate(toAngle: CGFloat, duration: TimeInterval)

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

class func rotate(toAngle: CGFloat, duration: TimeInterval, shortestUnitArc: Bool)

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

Creating Actions That Change a Node’s Animation Speed

class func speed(by: CGFloat, duration: TimeInterval)

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

class func speed(to: CGFloat, duration: TimeInterval)

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

Creating Actions That Change a Node’s Scale

class func scale(by: CGFloat, duration: TimeInterval)

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

class func scale(to: CGFloat, duration: TimeInterval)

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

class func scaleX(by: CGFloat, y: CGFloat, duration: TimeInterval)

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

class func scaleX(to: CGFloat, y: CGFloat, duration: TimeInterval)

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

class func scaleX(to: CGFloat, duration: TimeInterval)

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

class func scaleY(to: CGFloat, duration: TimeInterval)

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

Creating Actions to Show or Hide a Node

class func unhide()

Creates an action that makes a node visible.

class func hide()

Creates an action that hides a node.

Creating Actions That Change a Node’s Transparency

class func fadeIn(withDuration: TimeInterval)

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

class func fadeOut(withDuration: TimeInterval)

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

class func fadeAlpha(by: CGFloat, duration: TimeInterval)

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

class func fadeAlpha(to: CGFloat, duration: TimeInterval)

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

Creating Actions That Change a Sprite Node’s Content

class func resize(byWidth: CGFloat, height: CGFloat, duration: TimeInterval)

Creates an action that adjusts the size of a sprite.

class func resize(toHeight: CGFloat, duration: TimeInterval)

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

class func resize(toWidth: CGFloat, duration: TimeInterval)

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

class func resize(toWidth: CGFloat, height: CGFloat, duration: TimeInterval)

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

class func setTexture(SKTexture)

Creates an action that changes a sprite’s texture.

class func setTexture(SKTexture, resize: Bool)

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

class func animate(with: [SKTexture], timePerFrame: TimeInterval)

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

class func animate(with: [SKTexture], timePerFrame: TimeInterval, resize: Bool, restore: Bool)

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

class func setNormalTexture(SKTexture)

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

class func setNormalTexture(SKTexture, resize: Bool)

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

class func animate(withNormalTextures: [SKTexture], timePerFrame: TimeInterval)

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

class func colorize(with: UIColor, colorBlendFactor: CGFloat, duration: TimeInterval)

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

class func colorize(withColorBlendFactor: CGFloat, duration: TimeInterval)

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

Creating Physics Actions

class func applyForce(CGVector, duration: TimeInterval)

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

class func applyTorque(CGFloat, duration: TimeInterval)

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

class func applyForce(CGVector, at: CGPoint, duration: TimeInterval)

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

class func applyImpulse(CGVector, duration: TimeInterval)

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

class func applyAngularImpulse(CGFloat, duration: TimeInterval)

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

class func applyImpulse(CGVector, at: CGPoint, duration: TimeInterval)

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

class func changeCharge(to: Float, duration: TimeInterval)

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

class func changeCharge(by: Float, duration: TimeInterval)

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

class func changeMass(to: Float, duration: TimeInterval)

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

class func changeMass(by: Float, duration: TimeInterval)

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

class func strength(to: Float, duration: TimeInterval)

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

class func strength(by: Float, duration: TimeInterval)

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

class func falloff(to: Float, duration: TimeInterval)

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

class func falloff(by: Float, duration: TimeInterval)

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

Creating Audio Actions

class func play()

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

class func pause()

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

class func stop()

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

class func changePlaybackRate(to: Float, duration: TimeInterval)

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

class func changePlaybackRate(by: Float, duration: TimeInterval)

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

class func changeVolume(to: Float, duration: TimeInterval)

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

class func changeVolume(by: Float, duration: TimeInterval)

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

class func changeObstruction(to: Float, duration: TimeInterval)

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

class func changeObstruction(by: Float, duration: TimeInterval)

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

class func changeOcclusion(to: Float, duration: TimeInterval)

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

class func changeOcclusion(by: Float, duration: TimeInterval)

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

class func changeReverb(to: Float, duration: TimeInterval)

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

class func changeReverb(by: Float, duration: TimeInterval)

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

class func stereoPan(to: Float, duration: TimeInterval)

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

class func stereoPan(by: Float, duration: TimeInterval)

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

Removing Nodes from the Scene

class func removeFromParent()

Creates an action that removes the node from its parent.

Creating Actions That Perform Actions on a Node’s Child

class func run(SKAction, onChildWithName: String)

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

Creating Actions That Combine or Repeat Other Actions

class func group([SKAction])

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

class func sequence([SKAction])

Creates an action that runs a collection of actions sequentially.

class func `repeat`(SKAction, count: Int)

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

class func repeatForever(SKAction)

Creates an action that repeats another action forever.

Creating an Action to Introduce a Delay into a Sequence

class func wait(forDuration: TimeInterval)

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

class func wait(forDuration: TimeInterval, withRange: TimeInterval)

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

Creating Actions to Perform Inverse Kinematic Calculations

class func reach(to: CGPoint, rootNode: SKNode, duration: TimeInterval)

Creates an action that performs an inverse kinematic reach.

class func reach(to: CGPoint, rootNode: SKNode, velocity: CGFloat)

Creates an action that performs an inverse kinematic reach.

class func reach(to: SKNode, rootNode: SKNode, duration: TimeInterval)

Creates an action that performs an inverse kinematic reach.

class func reach(to: SKNode, rootNode: SKNode, velocity: CGFloat)

Creates an action that performs an inverse kinematic reach.

Creating Custom Actions

init?(named: String)

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

init?(named: String, duration: TimeInterval)

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

init?(named: String, from: URL)

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

init?(named: String, from: URL, duration: TimeInterval)

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

class func perform(Selector, onTarget: Any)

Creates an action that calls a method on an object.

class func run( () -> Void)

Creates an action that executes a block.

class func run( () -> Void, queue: DispatchQueue)

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

Reversing an Action

func reversed()

Creates an action that reverses the behavior of another action.

Inspecting an Action’s Animation Properties

var speed: CGFloat

A speed factor that modifies how fast an action runs.

var timingMode: SKActionTimingMode

The timing mode used to execute an action.

var timingFunction: SKActionTimingFunction

A block used to customize the timing function.

var duration: TimeInterval

The duration required to complete an action.

Constants

SKActionTimingMode

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

SKActionTimingFunction

The signature for the custom timing block.

Type Methods

class func animate(withWarps: [SKWarpGeometry], times: [NSNumber])

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

class func animate(withWarps: [SKWarpGeometry], times: [NSNumber], restore: Bool)

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

class func scale(to: CGSize, duration: TimeInterval)

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

class func warp(to: SKWarpGeometry, duration: TimeInterval)

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

Relationships

Inherits From