Creating the world
The first object of Box2D that you will create is the world that holds the simulation itself. In addition to the world, you will also create a few other things in the CreateWorld
function from the GameWorld.cpp
file:
void GameWorld::CreateWorld() { // create world b2Vec2 gravity; gravity.Set(0, -10.0f); world_ = new b2World(gravity); // tell world we want to listen for collisions world_->SetContactListener(this); // create the moving container that will hold all the game elements game_object_layer_ = CCNode::create(); addChild(game_object_layer_, E_LAYER_FOREGROUND); #ifdef ENABLE_DEBUG_DRAW debug_draw_ = new GLESDebugDraw(PTM_RATIO); world_->SetDebugDraw(debug_draw_); uint32 flags = 0; flags += b2Draw::e_shapeBit; // flags += b2Draw::e_jointBit; // flags += b2Draw::e_aabbBit; // flags += b2Draw::e_pairBit; // flags += b2Draw::e_centerOfMassBit; debug_draw_->SetFlags(flags); #endif }
We begin by creating a variable...