Game Development Reference
In-Depth Information
bodyDef.position.Set(320/worldScale,470/worldScale);
var polygonShape:b2PolygonShape=new b2PolygonShape();
polygonShape.SetAsBox(320/worldScale,10/worldScale);
var fixtureDef:b2FixtureDef=new b2FixtureDef();
fixtureDef.shape=polygonShape;
var groundBody:b2Body=world.CreateBody(bodyDef);
groundBody.CreateFixture(fixtureDef);
bodyDef.position.Set(320/worldScale,430/worldScale);
bodyDef.type=b2Body.b2_dynamicBody;
polygonShape.SetAsBox(30/worldScale,30/worldScale);
fixtureDef.density=1;
fixtureDef.friction=0.5;
fixtureDef.restitution=0.2;
var box2:b2Body=world.CreateBody(bodyDef);
box2.CreateFixture(fixtureDef);
bodyDef.position.Set(420/worldScale,430/worldScale);
var box3:b2Body=world.CreateBody(bodyDef);
box3.CreateFixture(fixtureDef);
var dJoint:b2DistanceJointDef=new b2DistanceJointDef();
dJoint.bodyA=box2;
dJoint.bodyB=box3;
dJoint.localAnchorA=new b2Vec2(0,0);
dJoint.localAnchorB=new b2Vec2(0,0);
dJoint.length=100/worldScale;
var distanceJoint:b2DistanceJoint;
distanceJoint=world.CreateJoint(dJoint) as b2DistanceJoint;
bodyDef.position.Set(320/worldScale,240/worldScale);
var box4:b2Body=world.CreateBody(bodyDef);
box4.CreateFixture(fixtureDef);
var rJoint:b2RevoluteJointDef=new b2RevoluteJointDef();
rJoint.bodyA=box4;
rJoint.bodyB=world.GetGroundBody();
rJoint.localAnchorA=new b2Vec2(0,0);
rJoint.localAnchorB=box4.GetWorldCenter();
var revoluteJoint:b2RevoluteJoint;
revoluteJoint=world.CreateJoint(rJoint) as b2RevoluteJoint;
addEventListener(Event.ENTER_FRAME,updateWorld);
stage.addEventListener(MouseEvent.MOUSE_DOWN,createJoint);
}
As usual, there's nothing to say about the creation of the box4 body, and I am
going to explain line-by-line joint creation, which starts with the definition of
b2RevoluteJointDef :
var rJoint:b2RevoluteJointDef=new b2RevoluteJointDef();
 
Search WWH ::




Custom Search