Game Development Reference
In-Depth Information
SKAction* fadeOutAction = [SKAction
fadeOutWithDuration:1.0];
[self.spaceShipSprite runAction:fadeOutAction];
In SpriteKit, there are many more actions for giving delays, changing content, invoking an
object or selector, calling blocks, and many special effects.
Similar to the individual actions, there are sequence and repeat actions, which fall under a
different category of actions provided by SpriteKit. The sequence action is meant for run-
ning actions in a particular sequence we want. As shown in the following code, two ac-
tions are created—one for fading out and the other for fading in the sprite. So, both the ac-
tions are fed to the sequence action in the order we want and it would run the sequence we
asked for:
SKAction* fadeOutAction = [SKAction
fadeOutWithDuration:1.0];
SKAction* fadeInAction = [SKAction fadeInWithDuration:1.0];
SKAction* sequenceAction = [SKAction
sequence:@[fadeOutAction, fadeInAction]];
[self.spaceShipSprite runAction:sequenceAction];
The repeat action allows actions to be repeated for a fixed number of time or to be re-
peated forever. So using the preceding sequence action, we do both.
• Animating the sequence for three times regularly:
SKAction* repeatThreeTimesAction = [SKAction
repeatAction:sequenceAction count:3];
[self.spaceShipSprite
runAction:repeatThreeTimesAction];
• Animating the sequence repeatedly forever:
SKAction* repeatForeverAction = [SKAction
repeatActionForever:sequenceAction];
[self.spaceShipSprite runAction:repeatForeverAction];
Another type of action is the group action. Several times in games we may need to repeat
a sequence of actions, which means running actions in a particular sequence for any inter-
val of time. As shown previously, two actions were created, one for fading out and second
Search WWH ::




Custom Search