Game Development Reference
This chapter introduces you to the essential building blocks of the cocos2d game engine.
You'll be using most of these classes in every game you create, so understanding what's
available and how the classes work together will help you write better games. Armed
with this knowledge, you'll find it a lot easier to start working with cocos2d.
Accompanying this chapter is an Xcode project called Essentials that includes
everything I discuss here, plus additional examples. The source code is full of com-
This chapter starts with a high-level overview of the cocos2d game engine architecture.
Because every game engine is different in the way game objects are managed and
presented on the screen, it's best to begin with an understanding of what the individual
elements are and how they fit together.
The cocos2d Scene Graph
Sometimes called a scene hierarchy, the scene graph is a hierarchy of every cocos2d
node that's currently active.
A cocos2d node is any object derived from the CCNode class. Most nodes, like CCS-
prite and CCLabelTTF , are displayed on the screen, but a few have no visual repres-
entation, including CCNode , CCScene , and CCLayer . They are no less important,
though, and they frequently cause confusion for new cocos2d developers.