Game Development Reference
In-Depth Information
Note I'll explain the use of the physics node in the next chapter. Technically,
you could use any other node type for the time being, but you'll need a physics
node in the next chapter. Because replacing a node with one of a different type
isn't currently possible in SpriteBuilder, it makes sense to use the physics node
right away.
The main reason for adding the player (and other game objects) as the child of another
node is to be able to move the level contents independently from the parallaxing back-
ground. If you were to continue using the Level1.ccb root node as the player's parent
node, the changes made to the player's parent position would offset all of the Level1.ccb
child nodes, including the background. That would make the background scrolling code
more complicated and harder to understand, and it would be difficult to add stationary
nodes, such as the in-game pause button to the level.
From the Node Library View, drag and drop a physics node onto the Level1.ccb stage. Set
its position to 0,0, and change its Name property to “physics” (that's for the next chapter).
In the Timeline view, drag and drop the player node so that it becomes a child of the
CCPhysicsNode as in Figure 3-18 by dropping it exactly on the CCPhysicsNode.
Figure 3-18 . The player node is now a child of a CCPhysicsNode
Note You may have noticed that you can't drag and drop the player node onto
the background node. This is because the background node is a Sub File
(CCBFile) node, which does not accept child nodes. There are other nodes that
can't have child nodes: Particle System, Label TTF, Label BM-Font, Button,
Text Field, Slider, and Scroll View. This limitation is imposed on nodes that
create or manage their branch of the node hierarchy. For instance, a button actu-
ally contains a sprite and a label node as children, while Scroll View and Sub
Search WWH ::




Custom Search