Working in Debug Mode with Box2D
Even tough Box2D doesn’t display anything on the screen it has a debug mode that you can use to see what Box2D is actually doing. Very useful of course. Now let’s see how to create a debug mode.
Setting the debug mode:
var debug_sprite:Sprite = new Sprite();
You need to pass a Sprite to the b2DebugDraw object and of course add
this Sprite on the screen so you can see the Box2D objects. You can
debug at a different scale but usually you pass the same scale value.
Note that all the examples in this article will be referencing a public
static const called SCALE and set to a value of 30. Also the setFlags()
method allows you to see different box2D features. You can set alpha for
the fill and the lines. Feel free to experiment.
Finally let’s update our debug mode as well:
world.Step(1 / 30, 10, 10);
That’s it, now everything we create in Box2D will be shown in our debug Sprite. Here again that was pretty easy. Now to see something we of course need to create something so let’s see that now.