2
votes

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

1
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
Thanks, it works. i have made zIndex to -1 of my background sprite and Physics objects are showing :)Ahsan
@Guru How I can bring it front? Please see my question here: stackoverflow.com/questions/22287420/…Narek
@Narek, its simple take your sprite z-order less than 0.Guru
@Guru I have a deeper problem with this: stackoverflow.com/questions/22288222/… 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

1 Answers

0
votes

You should use GLESDebugDraw when determining flags:

uint32 flags = 0;

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