Let's perform the following steps:
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.
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.
Polygon shapes must follow some restrictions, but at the moment because we only need an axis-aligned box, the
SetAsBox
method is all we need.polygonShape.SetAsBox(320/worldScale,10/worldScale);
The method requires two arguments: the half-width and the half-height of the box. In the end, our new polygon shape will have its center at pixels (320, 470), and...