Hi,
I've posted this over on cocos2d as well, but most folks over there use Chipmunk2d so I reckoned that this forum may be more appropriate.
I'm making an attempt to use Box2d with cocos2d, and I've got
everything working except the debug drawing. I can add bodies to my
world in a CocosNode, and simulate them (printing out their position
so i know they're moving). However, for some reason I can't get them
to show up.
I took the GLES-Render.mm from the Box2d project and added it to mine
and set the worlds debug draw object
debugDraw = new GLESDebugDraw();
world->SetDebugDraw(debugDraw);
debugDraw->SetFlags(debugDraw->e_shapeBit | debugDraw->e_aabbBit);
//debugDraw->SetFlags(0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 |
0x0020 | 0x0040 | 0x0080);
And when I step through world->Step(), I follow it all the way
to through and it appears to be calling all the right functions -
finds the bodies and shapes, then calls DrawPolygon, or DrawCircle
etc. But alas, no debug drawing shows up. In my game loop method, If I
update a sprite's position to a box2d body's position I can see it moving in
the simulation and colliding with (invisible) shapes that I've placed in the world, it is just the debug drawing that is non-visible.
I have a feeling I'm just missing an opengl call perhaps, but I really
have no idea. I've noticed a few differences between the way cocos2d sets up the projection matrix and viewport, and I've tried matching those calls (glOrthof, etc) to what is in Box2d's iphone demo. But not having any luck yet.
Any help is greatly appreciated. 🙂
Thanks,
Chris
I've posted this over on cocos2d as well, but most folks over there use Chipmunk2d so I reckoned that this forum may be more appropriate.
I'm making an attempt to use Box2d with cocos2d, and I've got
everything working except the debug drawing. I can add bodies to my
world in a CocosNode, and simulate them (printing out their position
so i know they're moving). However, for some reason I can't get them
to show up.
I took the GLES-Render.mm from the Box2d project and added it to mine
and set the worlds debug draw object
Code:
debugDraw = new GLESDebugDraw();
world->SetDebugDraw(debugDraw);
debugDraw->SetFlags(debugDraw->e_shapeBit | debugDraw->e_aabbBit);
//debugDraw->SetFlags(0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 |
0x0020 | 0x0040 | 0x0080);
And when I step through world->Step(), I follow it all the way
to through and it appears to be calling all the right functions -
finds the bodies and shapes, then calls DrawPolygon, or DrawCircle
etc. But alas, no debug drawing shows up. In my game loop method, If I
update a sprite's position to a box2d body's position I can see it moving in
the simulation and colliding with (invisible) shapes that I've placed in the world, it is just the debug drawing that is non-visible.
I have a feeling I'm just missing an opengl call perhaps, but I really
have no idea. I've noticed a few differences between the way cocos2d sets up the projection matrix and viewport, and I've tried matching those calls (glOrthof, etc) to what is in Box2d's iphone demo. But not having any luck yet.
Any help is greatly appreciated. 🙂
Thanks,
Chris