Game Development Reference
In-Depth Information
var actionSequence = SKAction.sequence([moveRightAction,
moveLeftAction])
var moveAction
= SKAction.repeatActionForever(actionSequence)
sampleNode.runAction(moveActionSequence)
Here you see the previous example, but now there is another action, repeatAc-
tionForever , that will run the moveAction forever. That's all it took—one line to
make all the previous actions run forever.
While this is a simple set of SKAction examples, there is almost no limit to how you
can leverage actions in your games. In the following sections of this chapter, I will show
you how to use some of this same code to move a collection of nodes back and forth
across the scene while also rotating the node through a collection of textures, giving the il-
lusion of node rotation.
Before moving on, there is one thing you should note. Take a look at all the methods used
to create the SKAction s. Note that all of these methods are class methods. This is the
pattern used to create all SKAction s. Currently there are no extensions of the SKAc-
tion class.
Using Actions to Move Nodes in the Scene
In the previous section, I told you I was going to show you how to move a collection of
nodes back and forth across the game scene. You have already seen how to do this using
the moveToX , sequence , and repeatForever actions.
The node that will be moving across the scene is a new node. If you open the
sprites.atlas folder, you will see several BlackHoleX.png images. Select the
first image in the list, BlackHole0.png . It should look like Figure 5-2 .
Figure 5-2 . The BlackHole node
Search WWH ::




Custom Search