Game Development Reference
In-Depth Information
bodyDef.position.Set(320/worldScale,
455/worldScale);
polygonShape.SetAsBox(5/worldScale,5/worldScale);
var body3:b2Body=world.CreateBody(bodyDef);
body3.CreateFixture(fixtureDef);
body3.SetLinearVelocity(new b2Vec2(100,-10));
stage.addEventListener(MouseEvent.CLICK,
updateWorld);
}
private function debugDraw():void {
var debugDraw:b2DebugDraw=new b2DebugDraw();
var debugSprite:Sprite=new Sprite();
addChild(debugSprite);
debugDraw.SetSprite(debugSprite);
debugDraw.SetDrawScale(worldScale);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
debugDraw.SetFillAlpha(0.5);
world.SetDebugDraw(debugDraw);
}
private function updateWorld(e:MouseEvent):void {
world.Step(1/30,10,10);
world.ClearForces();
world.DrawDebugData();
}
}
}
There's nothing new in the script. It places three bodies called body , body2 ,
and body3 , which are respectively a static floor, a vertical dynamic barrier,
and a small dynamic bullet.
As you can see, the bullet is fired at a quite high speed (100,-10) , and the
updateWorld function, which runs world step, is not called at every frame
but at every mouse click. This will allow you to run the simulation step by
step, as slow as you want, and see what happens.
 
Search WWH ::




Custom Search