Game Development Reference
In-Depth Information
The previous lines of code perform this task. Now let's see idol rotation.
var angle:Number=Math.round(b.GetAngle()*radToDeg);
The
GetAngle
method gets the angle of the body in radians. As I am sure you
feel more comfortable working with degrees, I converted radians to degrees
by multiplying
GetAngle
returned number by a variable called
radToDeg
,
which is defined on the first line of the
updateWorld
function.
To get degrees from radians, use the following formula:
Degrees = Radians * 180 / PI
To get radians from degrees, use the inverse:
Radians = Degrees * PI / 180
There is a lot of additional data we can get from the idol, but at the moment
let's just get some other information, the velocity.
var velocity:b2Vec2=b.GetLinearVelocity();
The
GetLinearVelocity
method gets the linear velocity of the center of
the mass and returns it in a
b2Vec2
object representing the horizontal and
vertical speed in meters per second.
As we still want to work with pixels, another conversion is needed:
var xVel:Number=Math.round(velocity.x*worldScale);
var yVel:Number=Math.round(velocity.y*worldScale);
The remaining lines just manage the output on the text field.