Action Initializers
Use these functions to create actions.
Overview
Most actions implement specific predefined animations that are done for you by SpriteKit. If your animation needs fall outside of the suite provided here, then you should:
Consider using the methods in Creating Custom Actions below (never subclass
SKAction)Consider the advice in Drive Game Logic
Choose an Initializer for the Property You Want to Alter
Most actions allow you to change a node’s properties and some actions specifically apply to specific nodes, like SKSpriteNode’s actions for animating its color or texture.
Here are the most common animated properties:
Changing a node’s
sizeor scaling propertiesChanging a node’s visibility or making it translucent
Changing a sprite node’s contents so that it animates through a series of textures
Colorizing a sprite node
Playing sounds
Removing a node from the node tree
Calling a block
Invoking a selector on an object
See Action Initializers for a full list of action types.
Chaining Actions
Actions can be chained together in multiple ways:
A sequence action has multiple child actions. Each action in the sequence begins after the previous action ends.
A group action has multiple child actions. All actions stored in the group begin executing at the same time.
A repeating action stores a single child action. When the child action completes, it is restarted.
To delay a subsequent action in the chain, insert a wait(forDuration:) action in the sequence, and remember that groups, sequences, and repeating actions may be nested.
Topics
Animating a Node’s Position in a Linear Path
Animating a Node’s Position Along a Custom Path
follow(_:duration:)follow(_:speed:)follow(_:asOffset:orientToPath:duration:)follow(_:asOffset:orientToPath:speed:)
Animating the Rotation of a Node
Controlling the Action’s Speed
Animating the Scaling of a Node
scale(by:duration:)scale(to:duration:)scale(to:duration:)scaleX(by:y:duration:)scaleX(to:y:duration:)scaleX(to:duration:)scaleY(to:duration:)
Animating the Transparency of a Node
Animating a Node’s Texture
resize(byWidth:height:duration:)resize(toHeight:duration:)resize(toWidth:duration:)resize(toWidth:height:duration:)setTexture(_:)setTexture(_:resize:)animate(with:timePerFrame:)animate(with:timePerFrame:resize:restore:)setNormalTexture(_:)setNormalTexture(_:resize:)animate(withNormalTextures:timePerFrame:)animate(withNormalTextures:timePerFrame:resize:restore:)colorize(with:colorBlendFactor:duration:)colorize(withColorBlendFactor:duration:)
Animating Properties of a Node’s Physics Body
applyForce(_:duration:)applyTorque(_:duration:)applyForce(_:at:duration:)applyImpulse(_:duration:)applyAngularImpulse(_:duration:)applyImpulse(_:at:duration:)applyImpulse(_:duration:)changeCharge(to:duration:)changeCharge(by:duration:)changeMass(to:duration:)changeMass(by:duration:)strength(to:duration:)strength(by:duration:)falloff(to:duration:)falloff(by:duration:)
Reversing an Animation
Animate the Warping of a Node
Controlling the Audio of a Node
playSoundFileNamed(_:waitForCompletion:)play()pause()stop()changePlaybackRate(to:duration:)changePlaybackRate(by:duration:)changeVolume(to:duration:)changeVolume(by:duration:)changeObstruction(to:duration:)changeObstruction(by:duration:)changeOcclusion(to:duration:)changeOcclusion(by:duration:)changeReverb(to:duration:)changeReverb(by:duration:)stereoPan(to:duration:)stereoPan(by:duration:)
Removing a Node from the Scene
Running Actions on Children
Chaining Actions
Delaying Actions
Performing Inverse Kinematics
Working with Inverse Kinematicsreach(to:rootNode:duration:)reach(to:rootNode:velocity:)reach(to:rootNode:duration:)reach(to:rootNode:velocity:)
Creating Custom Actions
init(named:)init(named:duration:)init(named:fromURL:)init(named:fromURL:duration:)customAction(withDuration:actionBlock:)perform(_:onTarget:)run(_:)run(_:queue:)