Game Development Reference
In-Depth Information
var bH:Number=20/worldScale;
var boxPos:b2Vec2=new b2Vec2(0,10/worldScale);
var boxAngle:Number=- Math.PI/4;
polygonShape.SetAsOrientedBox(bW,bH,boxPos,boxAngle);
fixtureDef.shape=polygonShape;
theIdol.CreateFixture(fixtureDef);
boxAngle=Math.PI/4;
polygonShape.SetAsOrientedBox(bW,bH,boxPos,boxAngle);
fixtureDef.shape=polygonShape;
theIdol.CreateFixture(fixtureDef);
var vertices:Vector.<b2Vec2>=new Vector.<b2Vec2>();
vertices.push(new b2Vec2(-15/worldScale,
-25/worldScale));
vertices.push(new b2Vec2(0,-40/worldScale));
vertices.push(new b2Vec2(15/worldScale,
-25/worldScale));
vertices.push(new b2Vec2(0,-10/worldScale));
polygonShape.SetAsVector(vertices,4);
fixtureDef.shape=polygonShape;
theIdol.CreateFixture(fixtureDef);
}
5.
And now, the core of the script, the code we'll insert into the
updateWorld function:
private function updateWorld(e:Event):void {
var radToDeg:Number=180/Math.PI;
world.Step(1/30,10,10);
world.ClearForces();
for (var b:b2Body=world.GetBodyList();
b; b=b.GetNext()) {
if (b.GetUserData()=="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);
 
Search WWH ::




Custom Search