Game Development Reference
In-Depth Information
flag it as sleeping and won't apply forces to it anymore—that is, unless an impulse or
force applied to the body is strong enough to make the body move or rotate again. This
trick allows the physics engine to save time by not processing the bodies that are at
rest. Unless all your game's dynamic bodies are in constant motion, you should enable
this feature as in Listing 12-3 .
The continuous physics setting causes Box2D to track collisions of fast-moving objects
more accurately. It effectively prevents fast-moving objects to penetrate or pass
through other objects at the expense of speed. In fact, you should probably leave this
setting disabled until you actually experience bugs due to fast-moving objects not col-
liding with each other.
The gravity passed to Box2D is a b2Vec2 struct type. It's essentially the same as
a CGPoint , because it stores x and y float values. In this case, and fortunately for us
in the real world too, gravity is a constant force. The 0, -10 vector is constantly applied
to all dynamic bodies, making them fall down, which in this case means toward the
bottom of the screen.
Debug drawing may be helpful during development but also has a negative impact on
performance. Unless you need it, it may be better to leave it disabled. The Hel-
loWorldLayer class performs the debug drawing in the draw method but encloses
it in #if DEBUG statement to make sure debug drawing is disabled in release builds:
#if DEBUG
-(void) draw
{
[super draw];
ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position);
kmGLPushMatrix();
world-> DrawDebugData();
kmGLPopMatrix();
}
#endif
Restricting Movement to the Screen
Search Nedrilad ::




Custom Search