Game Development Reference
In-Depth Information
6.
This is really easy. In the updateWorld function, we just have to retrieve
body position and rotation with GetPosition and GetAngle methods, and
rotate the sprites consequently. So the new content of the updateWorld
function is shown as follows:
var radToDeg:Number=180/Math.PI;
world.Step(1/30,10,10);
world.ClearForces();
if (! gameOver) {
for (var b:b2Body=world.GetBodyList(); b;
b=b.GetNext()) {
if (b.GetUserData()) {
b.GetUserData().asset.x=
b.GetPosition().x*worldScale;
b.GetUserData().asset.y=
b.GetPosition().y*worldScale;
b.GetUserData().asset.rotation=
b.GetAngle()*radToDeg;
if (b.GetUserData().name=="idol") {
var position:b2Vec2=b.GetPosition();
var xPos:Number=
Math.round(position.x*worldScale);
textMon.text=xPos.toString();
textMon.appendText(",");
var yPos:Number=
Math.round(position.y*worldScale);
textMon.appendText(yPos.toString());
textMon.appendText("\nangle: ");
var angle:Number=
Math.round(b.GetAngle()*radToDeg);
textMon.appendText(angle.toString());
textMon.appendText("\nVelocity: ");
var velocity:b2Vec2=b.GetLinearVelocity();
var xVel:Number=
Math.round(velocity.x*worldScale);
textMon.appendText(xVel.toString());
textMon.appendText(",");
var yVel:Number=
Math.round(velocity.y*worldScale);
textMon.appendText(yVel.toString());
for (var c:b2ContactEdge=b.GetContactList();
c; c=c.next) {
var contact:b2Contact=c.contact;
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
 
Search WWH ::




Custom Search