Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box2d in cocos2d-js ,How to debugDraw?? #885

Closed
XESDog opened this issue Oct 22, 2014 · 3 comments
Closed

Box2d in cocos2d-js ,How to debugDraw?? #885

XESDog opened this issue Oct 22, 2014 · 3 comments

Comments

@XESDog
Copy link

XESDog commented Oct 22, 2014

how to use b2debugDraw,the js-test.html model have not demonstrate

@zhaijialong
Copy link
Contributor

add this code to update function

var debugDraw = new Box2D.Dynamics.b2DebugDraw();
debugDraw.SetSprite(document.getElementById("test").getContext("2d")); // test is the id of another canvas which debugdraw works on
debugDraw.SetDrawScale(30.0);
debugDraw.SetFillAlpha(0.3);
debugDraw.SetLineThickness(1.0);
debugDraw.SetFlags(Box2D.Dynamics.b2DebugDraw.e_shapeBit | Box2D.Dynamics.b2DebugDraw.e_jointBit);
this.world.SetDebugDraw(debugDraw);
this.world.DrawDebugData();

and box2d use a different coordinate frame than cocos, so you need to do transform 180 degrees.
add this to the style of debug canvas

-webkit-transform:rotate(180deg); //and some other browsers' style

@XESDog
Copy link
Author

XESDog commented Oct 22, 2014

oh!!,thanks!

@adnanafzal565
Copy link

Can you send me complete code including the test canvas ?
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants