To create an oriented box shape, we will use a b2PolygonShape
method similar to SetAsBox
, yet more advanced and called the SetAsOrientedBox
method.
The arguments are the width and height of the box, the center of the box, also defined as a b2Vec2
object, and the rotation in radians.
Applying this concept, the
idol
function continues in the following way:var bW:Number=5/worldScale; var bH:Number=20/worldScale; var boxPos:b2Vec2=new b2Vec2(0,10/worldScale); var boxAngle:Number=- Math.PI/4;
The first two lines are quite understandable as we are defining the size of the box, which is same as the box we just created.
Looking at the third line, where I define the position, you could have some doubts. The center of the body of the first idol box was
(320,242)
in pixels, so why am I placing the second idol box at(0,10)
? Shouldn't it be placed near to the first idol box?That's the magic of compound objects you are about to learn. Now we aren't defining the position as...