Game Development Reference
In-Depth Information
The Box2D world is initialized in the initPhysics method by creating a new
b2World object with a gravity vector, as shown in Listing 12-3 . This also adds colli-
sions at the screen borders and enables debug drawing.
Listing 12-3. Initializing the Box2D World
-(void) initPhysics
{
b2Vec2 gravity;
gravity.Set(0.0f, -10.0f);
world = new b2World(gravity);
world-> SetAllowSleeping(true);
world-> SetContinuousPhysics(false);
debugDraw = new GLESDebugDraw(PTM_RATIO);
world-> SetDebugDraw(debugDraw);
uint32 flags = 0;
flags + = b2Draw::e_shapeBit;
// flags + = b2Draw::e_jointBit;
// flags + = b2Draw::e_aabbBit;
// flags + = b2Draw::e_pairBit;
// flags + = b2Draw::e_centerOfMassBit;
debugDraw-> SetFlags(flags);
// Define the ground body.
b2BodyDef groundBodyDef;
b2Body* groundBody = world-> CreateBody(&groundBodyDef);
// Define the ground box shape.
CGSize screenSize = [CCDirector sharedDirector].winSize;
float boxWidth = screenSize.width / PTM_RATIO;
float boxHeight = screenSize.height / PTM_RATIO;
b2EdgeShape groundBox;
int density = 0;
// bottom
 
 
Search Nedrilad ::




Custom Search