Game Development Reference
In-Depth Information
6.
At the end of the function, before returning the body, there are two calls to
the addWheel function, which creates a sphere in a given coordinate. Nothing
new again, but you'll see how our siege machine will take shape.
private function addWheel(pX:Number,pY:Number):b2Body {
var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.position.Set(pX/worldScale,pY/worldScale);
var circleShape:b2CircleShape=new b2CircleShape(0.5);
var fixtureDef:b2FixtureDef=new b2FixtureDef();
fixtureDef.shape=circleShape;
fixtureDef.density=1;
fixtureDef.restitution=0.5;
fixtureDef.friction=0.5;
var body:b2Body=world.CreateBody(bodyDef);
body.CreateFixture(fixtureDef);
return body;
}
7.
We complete the class with the debugDraw function, which also shows joints:
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|b2DebugDraw.e_jointBit);
debugDraw.SetFillAlpha(0.5);
world.SetDebugDraw(debugDraw);
}
8. And finally the updateWorld function:
private function updateWorld(e:Event):void {
world.Step(1/30,10,10);
world.ClearForces();
world.DrawDebugData();
}
 
Search WWH ::




Custom Search