Game Development Reference
In-Depth Information
dJoint.localAnchorB=new b2Vec2(0,0);
dJoint.length=100/worldScale;
var distanceJoint:b2DistanceJoint;
distanceJoint=world.CreateJoint(dJoint) as
b2DistanceJoint;
addEventListener(Event.ENTER_FRAME,updateWorld);
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP,keyReleased);
}
4.
And following are the callback functions. When the player presses left or
right arrow keys, left or right become true :
private function keyPressed(e:KeyboardEvent):void {
switch (e.keyCode) {
case 37 :
left=true;
break;
case 39 :
right=true;
break;
}
}
In the same way, when the player releases left or right arrow keys, left or
right become false :
private function keyReleased(e:KeyboardEvent):void {
switch (e.keyCode) {
case 37 :
left=false;
break;
case 39 :
right=false;
break;
}
}
5.
In the addCart function there are some changes, but mostly to distinguish
revolute joints with motors, which can be controlled with keyboard input
and passive revolute joints.
private function addCart(pX:Number,pY:Number,motor:Boolean):b2Body
{
var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.position.Set(pX/worldScale,pY/worldScale);
bodyDef.type=b2Body.b2_dynamicBody;
 
Search WWH ::




Custom Search