Game Development Reference
In-Depth Information
Figure 3-2 . An exploded view illustrating a typical cocos2d game scene layout
In this particular case, three layers help maintain the proper draw order of the sprites in
relation to each other: the background layer, the game objects layer, and the virtual
joypad layer. Using multiple layers in a scene is also helpful if you want to hide an en-
tire layer's nodes, move the layer and thus all the nodes it contains, or reorder the layer
so that its nodes are drawn above or behind another layer's nodes. You can even rotate
and scale a layer, which would rotate and scale all the nodes contained in that layer.
This makes using layers a powerful concept.
In this respect, the game scene is modeled using layers in just the way you edit an im-
age in an image-editing program such as Photoshop, Seashore, or GIMP. However, the
nodes (brush strokes) in each layer aren't static and instead remain individual elements.
The actual Scene object is just the container for all the layers (the actual image, so to
speak), just like a layer is a container for other nodes. Each of these nodes can run cus-
tom game logic, the scene, the layers, the individual nodes, the sprites, the labels, and
so on, depending on how you organize your code.
Any node can have any other node as a child, and every node in the hierarchy—except
for the scene itself—has one parent object, which is the object the node is a child of. If
you remove the node from the scene graph or you haven't added it yet, it won't have a
parent object. Note that this parent-child relationship of nodes is not to be confused
with inheritance in object-oriented programming. In other words, the parent node is not
the node's super class!
Search Nedrilad ::

Custom Search