Shooting the physics bird

We need to add some more lines to the birdRelease function:

private function birdRelease(e:MouseEvent):void {
  var distanceX:Number=theBird.x-slingX;
  var distanceY:Number=theBird.y-slingY;
  var velocityX:Number=distanceX*-1/5;
  var velocityY:Number=distanceY*-1/5;
  var birdVelocity:b2Vec2=new b2Vec2(velocityX,velocityY);
  var sphereX:Number=theBird.x/worldScale;
  var sphereY:Number=theBird.y/worldScale;
  var r:Number = 15/worldScale;
  var bodyDef:b2BodyDef=new b2BodyDef();
  bodyDef.position.Set(sphereX,sphereY);
  bodyDef.type=b2Body.b2_dynamicBody; var circleShape:b2CircleShape=new b2CircleShape(r); var fixtureDef:b2FixtureDef=new b2FixtureDef(); fixtureDef.shape=circleShape; fixtureDef.density=4; fixtureDef.restitution=0.4; ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.