Game Development Reference
In-Depth Information
Note
The springboard's base (
springstopper_metal
) needs no specific
Category
or
Masks
settings. Because it's a static body, it won't collide with other static
bodies anyway, and all other bodies should certainly collide with the spring-
board base.
If you run this now, you will notice that the spring is still passing through the
springstop-
per
node. There's one minor yet important detail I haven't mentioned yet. Select the
CCPhysicsSpringJoint
in
Spring.ccb
, and switch to the
Item Properties
tab. You'll see the
Collide bodies
check box isn't selected. This means that the two bodies connected to this
joint will not collide, regardless of their collision categories and masks. In this case, you
want the springboard to stop at the springstopper, so select the
Collide bodies
check box.
You can now publish and try this out. You may want to enable physics debug drawing to
verify that the springboard is still slightly inside the shaft when it stops at the springstop-
per. If it isn't, simply increase or decrease the height of the bottom segment of the spring-
stopper's collision shape. Also, verify that the player isn't blocked by the springstopper.
Adding a Spring Lock
A springboard that springs up the instant the level starts is pretty useless. You can easily
turn this springboard into a touch-activated spring that can even reset itself to its locked
position after a short time by using a distance joint.
In
Spring.ccb
, drag and drop a
Physics Distance Joint
onto the stage. Connect
Body A
with the springstopper. This will generate a static “world anchor” for this joint end, so it
doesn't actually matter what the position of the connected static physics body is. In fact,
you'll move that anchor far away shortly. Connect
Body B
with the
springboard_spring
.
On the joint's
Item Properties
tab, change
Anchor A
to
0x-200
. This moves the world an-
chor far below the spring. Set
Anchor B
to
32x32
, which about centers that end of the joint
on the spring.
The trick now is to enable both the
Minimum distance
and
Maximum distance
check
boxes. By default, the distances encompass the full length of the joint as it is now. The
joint will also draw two drag handles similar to the joint shown in
Figure 9-21
.
Don't drag
them. However, if you did drag them, you could click the
Enable
check box twice so that
it is turned off and on. Doing this will reset the
Minimum distance
and
Maximum distance
fields.
Search WWH ::
Custom Search