Using debug draw
While creating an object of the GLESDebugDraw
class, we need only pass in the pixel-to-meter ratio so the class knows exactly how much to scale the rendering of our physics objects. This class also gives us the option of choosing the elements we want to be drawn on to the screen. For this game, we only want our bodies' shapes to be drawn so all other flags are commented. Doing this will not render the shapes on the screen and we must add the following code to our layer's draw function:
#ifdef ENABLE_DEBUG_DRAW void GameWorld::draw() { CCLayer::draw(); ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); kmGLPushMatrix(); world_->DrawDebugData(); kmGLPopMatrix(); } #endif
An important thing to remember is that the GLESDebugDraw
class is intended for debugging purposes only and should be turned off unless absolutely required. This is why the preceding code is wrapped inside a pre-processor conditional. You might use this class the most in the initial stages...