Game Development Reference
In-Depth Information
}
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:Event):void {
world.Step(1/30,10,10);
world.ClearForces();
world.DrawDebugData();
}
}
}
You should be familiar with everything in it as it is just a minor modification of the
totem script as seen in the previous chapters. updateWorld , floor , and debugDraw
functions are exactly the same, while the sphere function creates a dynamic sphere
given its center and the radius in pixels.
The only difference is that the sphere function not only creates a sphere, but it also
returns its b2Body , which I am inserting in a class-level vector called sphereVector .
Test the movie and you'll see three of your spheres lying on the ground:
Each sphere is represented by a sphereVector item, from left to right we have
sphereVector[0] , sphereVector[1] , and sphereVector[2] .
It's time to make them jump. There are three dynamic bodies in this example because
you are about to learn three different ways to apply forces to bodies, each with its
pros and cons.
 
Search WWH ::




Custom Search