Game Development Reference
In-Depth Information
change you want to make to the scene.” There are many different uses for SKAction s,
but some of the more common uses of SKAction s are as follows:
Animating a node through a series of textures
Modifying the position of a node using its position property
Changing the visibility of a node using its hidden property
Adjusting the translucency of a node using its alpha property
Modifying the size of a node using its size property
Playing simple sounds
Colorizing a node
To use an SKAction , you have to perform only two steps: you create the action you
want to perform, and you tell the node you want to perform it on to run the action. An ex-
ample of this that would move a node to the right side of the scene over a period of two
seconds is shown here:
var moveRightAction = SKAction.moveToX(size.width,
duration: 2.0)
sampleNode.runAction(moveRightAction)
Another really cool feature of SKAction s is the ability to chain actions together. Take a
look at this example:
var moveRightAction = SKAction.moveToX(size.width,
duration: 2.0)
var moveLeftAction = SKAction.moveToX(0.0, duration: 2.0)
var actionSequence = SKAction.sequence([moveRightAction,
moveLeftAction])
sampleNode.runAction(actionSequence)
This bit of code will begin by moving the node to the right of the scene, and then when
that action is finished, it will move the same node to the left side of the scene. Another
nice feature of SKAction is the ability to repeat an action. Take a look at this snippet:
var moveRightAction = SKAction.moveToX(size.width,
duration: 2.0)
var moveLeftAction = SKAction.moveToX(0.0, duration: 2.0)
Search WWH ::




Custom Search