Cocos2d-X by Example Beginner’s Guide written by Roger Engelbert was published last month and, as a good geek, did not hesitate to order it in both digital and paperback versions and read it as soon as I could.
I have to say I’m not disappointed. On the contrary, I think the subjects are very interesting and the way the book takes you through the development of increasingly more comprehensive and complex games, you finish the book without realizing it and want to read another chapter, as if it were The Da Vinci Code!
Perhaps the only downside I found is that the book uses Cocos2d-2.0-x-2.0.4 when the actual version available is Cocos2d-2.1rc0-x-2.1.3 but, since this version has only been out for seven months and the author had to write the book in this time, we can’t criticize. In addition, on his website there is already a post with changes to adapt the code to the latest version, so another positive point for Roger.
I recommend this book to those who are interested in learning to develop using Cocos2D-X. For more info or content details keep reading to see a summary of each chapter.
Chapter 1 explains the installation of Cocos2D-X templates, preparing Xcode for creating Cocos2D-X projects. It describes the structure of a project, with different folders where we find the major classes of our game and the purpose of each one.
Here we also see, in a superficial way, the purpose of the objects CCDirector, CCScene and CCLayer and how they work together. We are not overwhelmed with too much theory from the beginning, enough to get started.
Once we have gotten familiarized with the environment, Chapter 2 shows the basics of creating and developing classes in C++ and how to perform memory management in Cocos2D-X projects without ARC.
We are introduced to CCScene, CCLayer, CCSprite and CCNode containers, and we learn how to use them to design a game.
CCObject is also discussed in this chapter and, in greater detail to the previous chapter, CCDirector as well as some of the most used cache objects (CCTextureCache, CCSpriteFrameCache and CCAnimationCache) and other classes that will make our development easier, such as CCActions or CCParticles.
Okay, you’re getting tired of the theory but do not worry, it gets good in Chapter 3. This chapter leads us by the hand to develop Air Hockey, the classic game of the arcades and one of the first apps that we enjoyed in the iPad (who didn’t go to the Apple Store to play with it?).
The chapter shows how to develop this game for iPad, supporting both screens, retina and non-retina. We learn how to manipulate sprites, add scoreboards and keep them updated with the score, insert images in relative positions and use sounds to make the game more attractive. Not bad for the first game!
Chapter 4 deals with sprites in an advanced way. We will use sprite sheets to optimize the loading of sprites, which we animate, scale and rotate to develop an addictive game: Sky Defense, this time for both iPhone and iPad.
Maybe, in the previous game, explosions have been somewhat poor but don’t worry, Chapter 5 adds special effects (yeah!) using particle systems, which give a more professional look to games involving shots or explosions .
We also see how to draw primitives (lines, circles, etc.) and with these we make Rocket Through, an attractive spacecraft game.
Chapter 6 shows how to quickly prototype a game we have in mind, so we can check if it’s also fun out of our head without having to spend much time with the visuals.
In this way we develop Victorian Rush, where we see how to implement jumps in response to the time the screen is pressed, to scroll the scene reusing the same blocks and to simulate that the protagonist floats when he deploys his umbrella, as if he were which Mary Poppins.
Also we learn how to manage the typology of the scenario so it appears to change randomly and to add difficulty based on the time.
Chapter 7 shows CCSpriteBatchNode class in more detail. Furthermore, based on the prototype we developed in the previous chapter, we add various sprites of the land, create a menu and make a tutorial for the game, great!
In the end we have a very visually attractive game and quite complete. What did I say? without realizing we are finishing the book and you are able to make a game with a menu and a tutorial.
Already in Chapter 8 we turn to more serious things: we enter the grounds of physical engine Box2D. Specifically we work with gravity, collisions, listeners and bodies (dynamic, static and kinematic). With all this we create a pool game, Virtua Pool style, who doesn’t remember it?
Thanks to lessons learned in the previous chapter, in Chapter 9 we also build a game based on Box2D, in addition we see different types of friction.
This time we have three scenes in the game, so we see how to move around them, thanks to CCScene, with it’s corresponding transitions, which makes our game much more attractive!
As icing on this cake, we learn to load settings for each level from plist files and use the accelerometer and notifications between objects.
At this point we’re practically experts in Cocos2D-X and we can think about making use of the most important aspect of our framework: the cross-platform. In Chapter 10 we see how to export the source code for our game to run on both Android and iOS, similar to the tutorial I wrote for Ray Wenderlich.