Game Development Reference
In-Depth Information
How to do it...
There is a wide variety of actions to be applied on nodes and sprites, some of which are lis-
ted next.
To understand this, we will take the spaceship as a sprite to apply different actions.
There are several individual actions provided by the SpriteKit framework. A few of them
are explained as follows:
Move Action : To move a sprite, call the class method shown below, specifying the
location where the sprite has to be moved and in what time. And then call the
runAction method on the sprite with the move action created.
SKAction* moveAction = [SKAction
moveTo:CGPointMake(100,100) duration:1.0];
[self.spaceShipSprite runAction:moveAction];
Rotate Action : To rotate a sprite, we have to specify an angle in radians, which
will make the sprite rotate by or to that angle in a specified time. So specify the
angle in degrees, convert to radians, and then feed it to the function thereby apply-
ing that action to the sprite.
CGFloat angleInDegree = 90.0;
CGFloat angleInRadian = angleInDegree * M_PI/180.0;
SKAction* rotateAction = [SKAction
rotateByAngle:angleInRadian duration:2.0];
[self.spaceShipSprite runAction:rotateAction];
Scale Action : To scale a sprite, we have to specify a scale factor, which will in-
crease or decrease the size of the sprite, depending on the scale factor given in a
time.
SKAction* scaleAction = [SKAction scaleBy:2.0
duration:2.0];
[self.spaceShipSprite runAction:scaleAction];
Fade Action : To make a sprite visible or invisible through animation, there are
methods for fading out and fading in a sprite. For now, fading out is shown in the
following code, which takes a parameter or the time over which to fadeout.
Search WWH ::




Custom Search