Game Development Reference
In-Depth Information
stance variable debugDraw . The debugDraw instance is then passed to the Box2D
world via the SetDebugDraw method. You can define what to draw by setting the
bits defined in b2DebugDraw , with the e_shapeBit being the most important be-
cause it draws the collision shapes of all bodies. Feel free to try out the other bits too,
but too much information is a real concern with debug drawing. It makes it harder to
see what you actually want to be seeing, and the more that's drawn, the lower the per-
formance will be.
You also have to override the draw method of the PinballTableLayer class and
call the debugDraw- > DrawDebugData() method to actually draw the debug
info. Because you don't want the end user to see the debug info, the draw method is
enclosed in an #ifdef DEBUG . . . #endif statement so that it's visible only
in debug builds:
-(void) draw
[super draw];
world- > DrawDebugData();
Adding the Ball
Can you imagine a pinball game without a pinball? I can't, so let's add one to the
PhysicsBox2DPinball01 project and have a look at its implementation. The
aptly named Ball class is derived from BodySprite and also implements the
CCTargetedTouchDelegate protocol for experimentation purposes (see Listing
13-8 ) .
Listing 13-8 . The Ball Class's Interface
Search Nedrilad ::

Custom Search