Book Image

Cocos2d-X Game Development Blueprints

By : Karan Sequeira
Book Image

Cocos2d-X Game Development Blueprints

By: Karan Sequeira

Overview of this book

Table of Contents (17 chapters)
Cocos2d-x Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...