Game Development Reference
This treelike hierarchy of nodes that you can create is what's called the scene graph ,
which I'll sometimes call the node hierarchy . For those familiar with programming
design patterns, you'll recognize this hierarchical structure as the Composite design
pattern. Figure 3-3 shows what the simplified node hierarchy of this scene looks like as
a tree structure.
Note that this particular scene/layer/nodes structure is not enforced by cocos2d, except
that the scene graph always has a CCScene class object as its root node. But other
than that, you can use any CCNode class instead of CCLayer to create your “layers.”
You could even add all of your nodes to the scene itself; if your project has only a
small number of nodes, that's perfectly reasonable.
I generally prefer to use the plain CCNode class over CCLayer for layering and
grouping objects; in most cases, the CCLayer class adds unnecessary overhead be-
cause it contains code to receive touch and accelerometer input in iOS apps and
handles keyboard and mouse input in Mac OS X apps. Strip away support for input
handling, and the CCLayer class is practically just a CCNode class. The same goes