Luckily, Box2D comes with a feature, debug draw , that will help us to see what's going on.
Debug draw will display what happens in the Box2D World, and we can enable it by calling world's
DrawDebugData
method right after theStep
method, in theupdateWorld
function:world.DrawDebugData();
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 worldScale:Number=30; public function Main() { world =new b2World(new b2Vec2(0,9.81),true); var bodyDef:b2BodyDef=new b2BodyDef(); bodyDef.position.Set(320/worldScale,30/worldScale); var circleShape...