Not sure if the post went through.
I have the book now. I am trying to make it work and I am almost there, but the
sprite is only glides correctly when thrown if I drag from top right to lower
left or lower left to top right.
If I throw it directly to the right it moves up and if I throw it to directly
to the left it goes down. If I throw it up it goes to the right. And if I throw
it down it moves to the left.
Here is the code (_object is the sprite being throw):
if(_drag == true){
var diffx:Number = initX - mx;
var diffy:Number = initY - my;
var speed:Number = 12;
var angle:Number = Math.atan2( diffx, diffy );
//var radians:Number = deg2rad(angle);
var xVel:Number = Math.cos(angle) * speed;
var yVel:Number = Math.sin(angle) * speed;
function deg2rad(deg:Number):Number {
return deg * (Math.PI/180);
}
function onLoop(evt:Event):void {
_object.x += xVel;
_object.y += yVel;
xVel *= 0.9;
yVel *= 0.9;
if (xVel < 0.05 && yVel < 0.05) {
_drag = false;
_stage.removeEventListener(Event.ENTER_FRAME, onLoop, false);
}
}
_stage.addEventListener(Event.ENTER_FRAME, onLoop,
false, 0, true);
//get the velocity and direction and make it go
another 100 pixels or more
}