2

I am new to box2d, i have to deal with the Physics Engine. i am creating fixtures and Physics body and set position. Now i want to view physical objects in Debug Mode. i have visited many forums and tried code, but no luck.

i am using the following code after creating my world

    m_debugDraw = new GLESDebugDraw( PTM_RATIO );
    _world->SetDebugDraw(m_debugDraw);
    uint32 flags = 0;
    flags += b2Draw::e_shapeBit;
    flags += b2Draw::e_jointBit;
    flags += b2Draw::e_aabbBit;
    flags += b2Draw::e_pairBit;
    flags += b2Draw::e_centerOfMassBit;
    m_debugDraw->SetFlags(flags);

and also override the Draw method and included GLES_Render.h as well. there are no compile errors but Physics objects in debug mode are not showing.

-(void) draw
{
    [super draw];
    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
    kmGLPushMatrix();
    _world->DrawDebugData();
    kmGLPopMatrix();
}

how to enable Debug Draw using cocos2d/Box2d version 2.1 OR is there any alternate way to view physics objects ?

Thanks

Ahsan
  • 41
  • 4
  • 4
    this debug shape's are drawn in 0th layer...it is visible only if your sprite's z-order is less than 0. try setting -1 for your sprite(sprite attached to body). – Guru Jul 19 '13 at 11:02
  • Thanks, it works. i have made zIndex to -1 of my background sprite and Physics objects are showing :) – Ahsan Jul 19 '13 at 11:11
  • @Guru How I can bring it front? Please see my question here: http://stackoverflow.com/questions/22287420/box2d-debug-draw-in-a-specific-layer – Narek Mar 09 '14 at 20:08
  • @Narek, its simple take your sprite z-order less than 0. – Guru Mar 10 '14 at 02:23
  • @Guru I have a deeper problem with this: http://stackoverflow.com/questions/22288222/primitives-and-sprites-z-index-in-cocos2d-x-3-0-is-not-consistent Primites are drawn under all sprites in Cocos2d-x :( Hence I can't bring them front. I don't know if this is a bug or it is as designed, but I can't do what I want. The only way is to use Z dimension, to bring front, but in that case I change the position of other coordinates to and the image is becoming bigger when you put bigger Z coordinates. – Narek Mar 10 '14 at 11:42

1 Answers1

0

You should use GLESDebugDraw when determining flags:

uint32 flags = 0;

flags += GLESDebugDraw::e_shapeBit;
flags += GLESDebugDraw::e_jointBit;
 .....
debugDraw->SetFlags(flags);