Game Development Reference
In-Depth Information
which will change the collision shape on the stage, as long as the
Item Physics
tab is selected. Tap the up and down arrow repeatedly to quickly switch
between the two shapes to verify that both shapes fit well, without any overlap.
Adding Joints to the Springboard
Now to the gist of it: making the springboard functional by using joints. This process will
take several steps, and I will show you how each step improves the spring behavior.
Start by dragging a node from the
Node Library View
onto the stage. Rename the node in
the Timeline to
springstopper
. On the
Item Physics
tab, check
Enable physics
, and then
change the body type to
Static
. The position of the node and its collision shape don't mat-
ter for now.
Now drag a
Physics Spring Joint
from the
Node Library View
onto the stage and select it.
Connect
Body A
of the joint with the
springstopper
node, and connect
Body B
with the
springboard_spring
node. Set
Anchor A
to
0x100
and
Anchor B
to
32x70
.
Select the
Enable
check box next to the
Rest length
field to enable the spring's desired
resting length, and then enter
10
in the
Rest length
field. This will be the size the spring
will want to expand or shrink to whenever it can. If enabled, the
Rest length
property adds
a drag handle on the spring joint as in
Figure 9-21
. To make the spring pull harder toward
the
Body A
anchor, increase
Stiffness
to
90
.
Figure 9-21
.
A spring joint with rest length enabled has a draggable length handle
Most likely, the joint will not point straight down onto the springboard, due to the spring-
stopper's position. You generally have two options: edit the joint's anchor, or change the
position of the node the joint is attached to. The latter option is always preferred whenever
you are free to move the node. Select the
springstopper
node, and change its position to
0x64
.
Notice that whenever you move a node, the joint anchor attached to it will move along
with it. This may or may not be what you want. It is generally advisable to move the
nodes into their desired positions before adding and connecting joints. Also note that joint
anchors need not be on or inside the connected node's collision shape or texture area. If
Search WWH ::
Custom Search