drawDebugData problem in cocos2d

Hi all,

i am not able to use drawDebugData in cocos2d in my app.

i have tried using GLES-Render.cpp. but still no luck. and also i dont know openGL.

Anyone can give a steps from for drawDebugData. So i can use it in my own app.

Anyone’s help appreciate a lot.

Thanks a Lot.

i’m also unable to see the debug data. there’s another thread here:
http://www.cocos2d-x.org/boards/6/topics/3108

and i’ve done everything listed in it. i downloaded sample code and everything is working in theory, i stepped over every instruction through debugging and it does what it is supposed to do, but nothing shows on screen

GLESDebugDraw::DrawSolidCircle is called, it does what it is supposed to do but nothing comes up on the screen

anyone able to help us? thanks in advance :slight_smile:

open ccConfig.h

#ifndef CC_SPRITE_DEBUG_DRAW
#define CC_SPRITE_DEBUG_DRAW 1// change from 0 to 1
#endif

hey jeet, thanks for the reply :smiley:

unfortunately, that doesn’t fix the problem we’re having. this flag draws a square border for each sprite, and it works perfectly in doing that

however what we are trying to figure out is how to show the bodies created in box2d. these are not necessarily square. if you want to check out what i mean, you can run the “tests” project in cocos2d-x and select the box2d testbed (http://i.imgur.com/2PDHp.png)

you’ll see samples of box2d’s drawDebugData feature. (http://i.imgur.com/ItfYz.png) it draws the bodies created in box2d using the GLESDebugDraw class, found in file GLES-Render.cpp

what i’m trying to do here is to have the bodies drawn on top of my sprites, so i can see how they relate in my gameplay screen

i’ve done that before in cocos2d for iPhone, but i have since quit the studio i used to work for and i don’t have access to the code :stuck_out_tongue:

again, any help is appreicated

Hi All,

After all its working fine for me. I have just copied GLES-Render.h and .cpp, and added these 2 files in project.

  1. Include this header file #include “GLES-Render.h”
  2. Create an instance variable GLESDebugDraw m_debugDraw;
  3. Add this code during initialization.
    m_debugDraw = new GLESDebugDraw(1.0);
    uint32 flags = 0;
    flags = 1 * b2DebugDraw::e_shapeBit;
    flags
    = 1 * b2DebugDraw::e_jointBit;
    flags = 1 * b2DebugDraw::e_aabbBit;
    flags
    = 1 * b2DebugDraw::e_pairBit;
    flags += 1 * b2DebugDraw::e_centerOfMassBit;
    m_debugDraw~~>SetFlags;
    m_world~~>SetDebugDraw(&m_debugDraw);
  4. And Finally add this code where your game is drawing(Ex: draw())

glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

m_test~~>m_world~~>DrawDebugData();

// restore default GL states
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

Compile it and there you go. You are finally seeing there.

Let me know if u have doubts or any help.

Thanks.

funny

after a lot of trial and error the one thing that was messing it up was the parameter in the GLESDebugDraw initialization.

turns out if you do this m_b2dDebugDraw = new GLESDebugDraw( PTM_RATIO ); it’ll create VERY small bodies, who are by all means invisible :confused:

does the debugdraw layer show over or under the sprites? i got them to show but they’re behind the sprites so i can’t really see what i want to see unless it’s a transparent sprite

hi avinash, from where did you got those files
“GLES-Render.h and .cpp”

@jeet: i have copied those 2 files from Box2DTestBed folder.

@cassiano rocha: Do u mean u want to draw a sprite in front of box2d debug draw.?

@cassiano rocha:

if ur answer is yes then follow the steps.

  1. Create a sprite.
  2. Create a body and shape.
  3. Create a body def
    b2BodyDef spriteBodyDef;
  4. Add this line
    spriteBodyDef.userData = sprite;
  5. And finally add these lines in update or tick method
    for(b2Body b = _world~~>GetBodyList; b; b=b~~>GetNext) {
    if != NULL) {
    CCSprite
    sprite = (CCSprite )b~~>GetUserData;
    b2Vec2 b2Position = b2Vec2;
    float32 b2Angle =~~1
    CC_DEGREES_TO_RADIANS(sprite.rotation);

b->SetTransform(b2Position, b2Angle);
}
}

UFFFFFFFFFF
That’s it for now. Finally you got the answer…

Thanks.

yeah i got all that stuff down :slight_smile:

thanks anyway though! very helpful :smiley:

what i wanted was for the box2d debugdrawdata to show on top of my sprite. right now, i can’t tell where the actual box2d bodies are because the debug draw data is behind the sprites

like this

there are 2 bodies in this picture, a circle and a square. however, only half of the circle is show because the sprite for the square is on top of the body for the square

i wanted the pink circle to be drawn ON TOP of everything, so i could see when they collided

thanks again for helping out :slight_smile:

@cassiano rocha

I think on my view of perspective i dont think u can draw debug on top of sprite. But there is only one way out u can try setting alpha for sprite and u can see both.

And about the color for draw debug data, u can go look into DrawDebugData() in b2World.cpp, u will find lots of if conditions like e_shapeBit, e_jointBit, e_pairBit, etc. there u will be seeing line
DrawShape(f, xf, b2Color(0.5f, 0.5f, 0.3f)); try to change the values in 3rd parameter in the function to get the exact color u want.

I think this posts will be helpful for u.

Feel free if u have more doubts.

Thanks.

hi again. which version of cocos2d-x are you using ? i am getting errors even after including those files. i am using version 11 with visual studio 10.

@jeet: i am using VS 2008 and cocos2d 0.11.0.

  1. where did u include those files. is it in VS, if so that won’t be work unless if u add the files in mkb file and start running it.

  2. Did u add instance variable “GLESDebugDraw m_debugDraw;” in header file, if not add it.

  3. Try to use b2Draw instead of b2DebugDraw.

  4. r u using “m_world” or “world”.

Thanks.

now, i got to know that the draw method gets called automatically.
i was thinking where is it being called. and so i was not implementing it :slight_smile: thanks for all the help
one thing is missing

GLESDebugDraw *m_debugDraw;

in header :slight_smile:

maybe the reason is that:
DebugDraw set zOrder of e_shapeBit as 0. The bg sprite covered it;
rm the bg sprite you will see it.
try it…

http://www.cocos2d-x.org/boards/6/topics/3831