Creating a box shape

Let's perform the following steps:

  1. First, body and fixture definitions can be reassigned to define our new body. This way, we don't need to declare another bodyDef variable, but we just need to reuse the one we used for the creation of the sphere by changing its position:
    bodyDef.position.Set(320/worldScale,470/worldScale);

    Now the body definition is located in the horizontal center, and close to the bottom of the screen.

  2. To create a polygon shape, we will use the b2PolygonShape class:
    var polygonShape:b2PolygonShape=new b2PolygonShape();

    This way we create a polygon shape in the same way we created the circle shape earlier.

  3. Polygon shapes must follow some restrictions, but at the moment because we only need an axis-aligned box, ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.