Game Development Reference
In-Depth Information
In this case, we won't destroy/kill it at once, but we are going to delegate
it to the updateWorld function after performing the step. We don't want to
remove bodies from the world while the step is currently being calculated,
so we just mark it as a body to be removed changing its custom data in the
following way:
fixtureA.GetBody().SetUserData("remove");
11. The same concept is then applied to the second body, and finally in the
updateWorld function all bodies marked with remove will be destroyed.
private function updateWorld(e:Event):void {
world.Step(1/30,10,10);
world.ClearForces();
for (var b:b2Body=world.GetBodyList();
b; b=b.GetNext()) {
if (b.GetUserData()=="remove") {
world.DestroyBody(b);
}
}
world.DrawDebugData();
}
12. Test the movie, aim and shoot, and you should see bricks and pigs being
removed from the world.
That's it, your Angry Birds level is developing more and more as you learn new
Box2D features.
 
Search WWH ::




Custom Search