Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by zaemz

Hey guys,

I'm having a frustrating time getting Box2D's debug drawing to simple draw the shapes over the top of the game, rather than not displaying any sprites or anything from the game itself.

Game's init method:

init: function() {
    Box2D.SCALE = 0.05;
    // Initial Level/Screen Load
    this.loadLevel(LevelAnimationexamples);
    /* Bindings and other stuff */
    this.debugDrawer = new ig.Box2DDebug(ig.world);
},

// Drawing function:
draw: function() {
    // Draw all entities and backgroundMaps
    this.parent();
    // Add your own drawing code here
    this.debugDrawer.draw();
}

I don't have any other shapes than boxes, and I haven't overwritten any drawing methods for any of the entities or the world.

If I comment out this.debugDrawer.draw(); I get this:

/><br />
<br />
When I leave the code in, I get this:<br />
<br />
<img src=

1 decade ago by Joncom

Had the same issue.
This version does what you want.

1 decade ago by Yojimbo

Aw, man, you're beautiful! Would you be able to explain the differences and how this works vs. how the other version doesn't? Is it a matter of context, was the other version drawing over the top of the canvas?

1 decade ago by Joncom

The older version allows Box2D to directly access the context draw methods. This means that Box2D calls clearRect before drawing shapes, which erases everything drawn up until that moment. The version I posted uses custom draw methods allowing more control over the whole process.

1 decade ago by Yojimbo

Awesome, thank you for the explanation. I understand it now. Really, thank you. This is a large help.

1 decade ago by Joncom

Quote from Yojimbo
Awesome, thank you for the explanation. I understand it now. Really, thank you. This is a large help.
You're welcome.

1 decade ago by dominic

@Joncom: I updated the physics example on the download page and the plugin on github with your debug drawer code. I hope that's okay with you?

Thank you!

1 decade ago by Joncom

Quote from dominic
@Joncom: I updated the physics example on the download page and the plugin on github with your debug drawer code. I hope that's okay with you?
Sure, no problem.
Page 1 of 1
« first « previous next › last »