Summary
At the beginning of this chapter, we had our first contact with a Cocos2d project. We created a new project and took an overview of it, understanding some of the classes that are part of this framework.
Then we were introduced to CCNode
, one of the main classes, as it's the class parent for some of the most important objects we will use when developing games. Also, we showed how the scene graph should look, with a parent CCScene
node as root and the different children nodes hanging from it.
You learned how to create a scene and add sprites to it, taking into account their anchor point to position them in the desired place. You also learned to add a background image with a customized z-order to be sure it lies behind the rest of the nodes.
I explained to you the characteristics to bear in mind when developing a game for both iPhone and iPad devices, such as screen resolution and relative positions.
Then you enabled user interaction to handle touches, which you used to know where to move the yeti using the CCActionMoveTo
action. At the same time, you learned how to keep a sprite within the screen limits.
You learned how to set up a bunch of enemies, snowballs in this case, in an array, initializing their positions to keep them out of view waiting to attack. At this point, you learned how to get one snowball randomly and to apply a horizontal movement until it reached the right-hand edge of the screen.
Also, you handled the collisions between the snowballs and the yeti and took advantage of it to create a tint and blink action to execute when a collision happens.
To give some playability to the game, you learned how to place labels using their anchor points and how to initialize and update their text.
Toward the end of the chapter, you learned where you can get some audio sources and how you can create your own. Once you had the background music and the sound effects, you learned how to use them in your game.
In the last section of the chapter, you learned how to declare a condition to finish the game and which actions are needed to illustrate the game is over.
Now that we know how to load and move sprites, let's take them further to create complex objects and realistic effects.