Placing the physics bird

This is when Box2D comes into play. As we are approximating the bird with a circle, we need to create a Box2D circle in the same point from where the player released the mouse.

Change the birdRelease function in the following way:

private function birdRelease(e:MouseEvent):void {
  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);
  var circleShape:b2CircleShape=new b2CircleShape(r);
  var fixtureDef:b2FixtureDef=new b2FixtureDef();
  fixtureDef.shape=circleShape;
  fixtureDef.density=4;
  fixtureDef.restitution=0.4;
  fixtureDef.friction=0.5;
 var physicsBird:b2Body=world.CreateBody(bodyDef); ...

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.