Game Development Reference
In-Depth Information
Note that the physics simulation is blissfully unaware of the node draw order. Despite the
ball being sorted in between the two types of chain elements, it will still dangle perfectly
fine at the end of the chain.
Caution Physics-enabled bodies ignore their node's parent-child relationship.
This means a physics-enabled child node will not move if its parent moves. The
physics engine knows no parent-child concept and will therefore treat all
physics-enabled bodies as independent of one another. I strongly recommended
that you design all complex physics objects without any parent-child relation-
ships, except where the child items do not have physics enabled and should fol-
low along with their physics-enabled parent node. You will see an example in
the discussion of the Spring object, which you'll add later in this chapter.
Now open the Level1.ccb , and place an instance of Chain.ccb somewhere near the play-
er's starting position. If you publish and run this now, the chain will not behave at all like
a chain. Instead, it will fall down and its individual pieces will come apart because you
haven't connected them with joints yet.
Adding Pivot Joints to the Chain
Let's make this a chain that deserves its name. Open Chain.ccb and, from the Node
Library View , drag and drop a Physics Pivot Joint onto the stage. This will add a pink
circle object that, when selected, shows two additional, smaller circles underneath it. See
Figure 9-4 .
Figure 9-4 . Dragging a connection from the pivot joint on the right to the hook node on the left
Notice that the new joint added itself as a CCPhysicsJoint in the Timeline under the Joints
group. You can select a joint like other nodes by clicking on it either in the stage or in the
Search WWH ::




Custom Search