Game Development Reference
In-Depth Information
Actions
Actions are one of the ways to add life to your game and make things interactive.
Actions allow you to perform different things such as moving, rotating, or scaling
nodes, playing sounds, and even running your custom code. When the scene
processes its nodes, actions that are linked to these nodes are executed.
To create a node, you run a class method on an action that you need, set its properties,
and call the runAction: method on your node with action as a parameter.
You may find some actions in the touchesBegan: method in ERGMyScene.m . In this
method, you can see that a new node (of the type SKSpriteNode ) is created, and then
a new action is created and attached to it. This action is embedded into another action
that makes it repeat forever, and then a sprite runs the action and you see a rotating
sprite on the screen.
To complete the preceding process, it took only five lines, and it is very intuitive.
This is one of the Sprite Kit strengths—simplicity and self-documenting code.
As you might have noticed, Apple names methods in a simpler way so that you
can understand what it does just by reading the method. Try to adhere to the
same practice and name your variables and methods so that their function can be
understood immediately. Avoid naming objects a or b , use characterSprite or
enemyEmitter instead.
There are different action types; here we will list some that you may need in your
first project:
Move actions ( moveTo:duration: , moveBy , followPath ) are actions
that move the node by a specified distance in points
Rotate actions are actions that rotate your nodes by a certain angle
( rotateByAngle:duration: )
Actions that change node scale over time ( scaleBy:duration )
Actions that combine other actions ( sequence: to play actions one
after another, and repeatAction: to play an action a certain amount
of times or forever)
There are many other actions and you might look up the SKAction class reference if
you want to learn more about actions.
 
Search WWH ::




Custom Search