Game Development Reference
In-Depth Information
drop one chainball_ball.png (the leftmost image in the top row in Figure 9-2 ) onto the
stage.
Make sure all sprites are children of the root node, because you don't want them to be
children of each other. Positions don't matter yet—you'll first edit the physics properties.
Select the letter-8 chain, and on the Item Physics tab, select the Enable Physics check box.
You should leave all physics properties at their default values. You may want to edit the
physics shape to make the rectangle slightly smaller, but don't add any vertices—there's
no need to make the chain's collision shape more detailed than a rectangle. With this
done, you can copy (Cmd+C) and paste (Cmd+V) the node twice so that you have a total
of three chains that look like an “8”.
Proceed to do the same for the letter “l” chain node. Select it, select Enable Physics , and
definitely edit its collision shape to make it smaller. Zoom the view in and out with Cmd+
and Cmd- to be able to edit the collision shape more precisely. After editing the collision
shape, create two additional copies of the sprite. You should now have a total of six chain
sprites, three of each kind.
Now select the ball sprite and also select its Enable Physics check box. But in this case
change its Physics Shape to Circle , and set the Corner radius to 42 . Since the collision
shape is offset slightly from the ball's center, click and drag its center handle to move the
collision circle so that it is wholly contained within the ball and just about centered. It
doesn't need to be perfectly centered. You should also change the ball's density to 0.5 ;
otherwise, the player will have a hard time pushing the ball out of the way.
Finally, go to the Node Library View and drag and drop a plain node onto the stage, mak-
ing it a child node of the root node like the others. This will become the “hook” node for
the chain, marking the spot where the chain will be affixed to the world so that the chain
won't simply fall down.
Move the hook node slightly upward by changing its position to 0x10 so that the topmost
chain element will correctly revolve around the hook. On the Item Physics tab for the
CCNode , check Enable Physics and change the body's type to Static . Also, set the Physics
Shape to Circle , and change the Corner radius to 8 . You should also rename this node to
hook in the Timeline.
Now arrange these images in the pattern shown in Figure 9-3 .
Search WWH ::




Custom Search