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); physicsBird.CreateFixture(fixtureDef); removeChild(theBird); stage.removeEventListener(MouseEvent.MOUSE_MOVE,birdMove); stage.removeEventListener(MouseEvent.MOUSE_UP,birdRelease); }