Game Development Reference
In-Depth Information
Creating compound bodies
The idol is the main character in Totem Destroyer, we can't represent it with just a
box, or the curse of the totem will persecute us forever.
I was thinking about something like the following figure:
This is what I call an idol, and this is what we are going to build with Box2D.
On the left-hand side, the outline of the bodies forming the idol, and on the right-
hand side the finished idol silhouette.
The first thing you can see is that the idol is made by more than one body joined
together to create a single, complex body. Remember Box2D only works with convex
polygons. Unlike totem bricks, which are just single boxes stacked, we need to merge
all the idol objects in some way.
Easy things first. We'll start with the vertical box that we already know how to build,
and we are going to build it in the Main function just after building the last totem brick.
public function Main() {
world=new b2World(new b2Vec2(0,5),true);
debugDraw();
brick(275,435,30,30);
brick(365,435,30,30);
brick(320,405,120,30);
brick(320,375,60,30);
brick(305,345,90,30);
brick(320,300,120,60);
idol(320,242);
addEventListener(Event.ENTER_FRAME,updateWorld);
}
 
Search WWH ::




Custom Search