Using debug draw to test your simulation

Luckily, Box2D comes with a feature, debug draw , that will help us to see what's going on.

  1. Debug draw will display what happens in the Box2D World, and we can enable it by calling world's DrawDebugData method right after the Step method, in the updateWorld function:
    world.DrawDebugData();
  2. Once we've told the world to display the debug draw after each iteration, we need to define the visual settings used by debug draw. Add the following lines to your Main class:
    package { import flash.display.Sprite; import flash.events.Event; import Box2D.Dynamics.*; import Box2D.Collision.*; import Box2D.Collision.Shapes.*; import Box2D.Common.Math.*; public class Main extends Sprite { private var world:b2World; private var ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.