Game Development Reference
In-Depth Information
I think gravity is a bit on the low side. Feels too moon-ish, it should be more earth-like. Or
just stronger. Newton would have rejoiced if he'd been able to change gravity as easily as
in SpriteBuilder.
Then you'll create borders enclosing the level, preventing the player from leaving the
playable area as well as funneling toward the exit.
Changing Gravity
To change gravity, open the
Level1.ccb
and select the physics node (if it was not re-
named, it's listed as
CCPhysicsNode)
in the Timeline. On its
Item Properties
tab, there is a section labeled
CCPhysicsNode
that has the
Gravity
property, as seen
in
Figure 4-5
. Change the gravity Y value from its default value of -100 to -200. The
value is negative because the positive Y axis in Cocos2D extends upward, but gravity is a
force pointing downward.
Figure 4-5
.
Increase CCPhysicsNode gravity to -200
Note that gravity is not a single value but a vector with x/y components. There's nothing
stopping you from adding a little sideways gravity, although that would be rather unusual.
Once more, publish, build, and run. See how you like the new gravity. Feel free to go back
to the
GameScene.ccb
root node and play around with the three
_player
values as
well as gravity to get a feel for more or less extreme values. When you are done experi-
menting, you may want to revert the values to the values in
Figure 4-4
and
Figure 4-5
, re-
spectively. Otherwise, different values may introduce unpredictable behavior later in the
topic, or simply prevent you from completing the level.
You should leave the
Sleep time threshold
property as is. It determines how
quickly physics bodies will go to sleep, a state where they rest without moving to reduce
the load on the CPU. Sleeping bodies will awake when forces are applied to them, and a
body must have very little velocity and angular momentum to start sleeping. This setting
Search WWH ::
Custom Search