What I see is that the debug information doesn’t align with the sprite on screen. It almost out of the sight.
Please note that I use latest version 2.1 from this website’s download link.
I have the same problem.
(Using the latest clone of cocos2d html5 from github (https://github.com/cocos2d/cocos2d-html5))
I set debug draw with almost same code and get a similar result.
Searched everywhere but haven’t found a way to get debugdraw and game aligned.
Than I came up with a very stupid idea to get it kinda work…
I created a second canvas on html named it “box2dDebugCanvas”
Told debugDraw to draw on this canvas instead of sharing it with cocos2d.
And I got the result in the attached file, my game is on the top, and debugdraw on the bottom in separate canvases.
but I had to flip debugDraw canvas vertically as It showed upside down by css: style="-webkit-transform:scaleY(–1);
I can not say it’s solved, of course it isn’t. But helps to see where are box2d bodies until it is solved.
Finally I can not stuck at this problem and continue making my game.
I keep it noted and will be look back later due to at the moment I switched to use chipmunk for the sake of continuing my project.
You’re right about y-axis, it flips me up side down the same.
I guess it relates about anchor position of the parent node, and scaling. I tried once to align debug nodes to sprite nodes, almost get it to perfectly aligned but have to do several work around like flipping / offset with winSize’s width and height. Your solution would erase those.
I have included my modified version of box2d to fix the position of the debug box positions in case anyone is requiring it.
I too ran into the problem of having the positions of the debug boxes around box2d objects out of place.
So I inverted the Y-axis drawing coordinate by multiplying them by –1 and added an offset which you set inside you main application js file, usually myApp.js by default, or where ever your setting up the world.
You can set the offset by using the method SetOffsets({x:,y:}) with the b2DebugDraw object you’ve defined. From the example in the first post on in this thread
1 //set up debug draw
2 var debugDraw = new b2DebugDraw();
3 debugDraw.SetSprite(cc.renderContext);
4 debugDraw.SetDrawScale(PTM_RATIO);
5 debugDraw.SetFillAlpha(0.3);
6 debugDraw.SetLineThickness(1.0);
7 debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit | b2DebugDraw.e_centerOfMassBit);
8 this.world.SetDebugDraw(debugDraw);
you could use: debugDraw.SetOffsets({x:,y:})
the parameters that the offsets take is a JSON notation object with a x value and y value that take in values that you want to be the offsets
e.g. ( { x : 10, y: 16 } )
this will draw the boxes 10 extra meters to the right and 16 extra meters to the top.
I noticed this sin’t the case for the latest git pull of the cocos2dhtml repo, I only needed to flip the boxes. I wasn’t required to set any offsets.
Actually in the latest git report version, I still had to invert the positions y-axis…so it means you don’t need to set an offset, but I still had to use my modified version of box2d…just without setting an offset.
Actually in the latest git report version, I still had to invert the positions y-axis…so it means you don’t need to set an offset, but I still had to use my modified version of box2d…just without setting an offset.
Hello,
How did you manage to fix this?
I’m having the issue where the debug’s y-axis is inverted, and the origin is in the center of the canvas. If I use Eralp’s method of putting it in another canvas, then the origin is fine, but the canvas is inverted and I know how to flip it here. However, if I flip the context in cocos2d, then everything will get flipped as well using my method.
The SetOffset method is there to correct the position of the boxes…you’ll bed to set offsets to have the boxes in the correct position. Use the method to offset the boxes till they are in the correct position
The SetOffset method is there to correct the position of the boxes…you’ll bed to set offsets to have the boxes in the correct position. Use the method to offset the boxes till they are in the correct position
So I’m using the setOffset right under the setFlags method. No matter what values I put in, it only moves one of the boxes. Also, if I put a negative value, both of the boxes don’t show up. I’m assuming they’re being drawn off the screen.
This is the image with debugDraw.SetOffsets({x:‘0’,y:‘10’})
As you can see, only the left box gets moved down.
just so I know the positions, where’s the vertical shape suppose to be on the screen and where is the vertical shape suppose to be
>
plus is the x-axis okay?
>
Also… are you using SetAsBox or just Set?
>
and are you using b2Polygonshape or a different shape?
So I went into Box2d.js and got it to work and then I realized that when using setOffsets you need to use numbers without the quotes contrary to the example.
Same as you, I’m sure the items are there in the backgroud but for now, I haven’t any other trick than to add another canvas.
This is wrong I feel, but it’s the only way I can think of at the moment.
I’m guessing Layer z index or something, but can’t solve it properly.
I have created a class to solve this, here is the code:
(It just flips the drawing context at execution time and as Node you can set ZOrder property to force it to be on top)
Then add the node in your layer and provide the world reference
// creating physics world
var world = new b2World(new b2Vec2(0, -10), true);
world.SetContinuousPhysics(true);
this.world = world;
// initializa debug
var drawNode = new DebugBox2DNode(world);
this.addChild(drawNode);