I am trying to get the cue to stop rotating when it is in the MOUSE_DOWN event, but continue to add the distance of mouseX and mouseY to the distance of the cue from the cueball. In other words, for the cue to slide along the line the cue is aimed down.
Cue.addEventListener(Event.ENTER_FRAME, aimCue);
Cue.addEventListener(MouseEvent.MOUSE_DOWN,StartToShoot);
addEventListener(Event.ENTER_FRAME,MoveBalls);
public function aimCue(event:Event)
{
var dx:Number = Cueball.x - Cue.x;
var dy:Number = Cueball.y - Cue.y;
var angle:Number = Math.atan2(dy,dx);
Cue.rotation = angle * 180 / Math.PI;
Cue.x = mouseX;
Cue.y = mouseY;
}
public function StartToShoot(event:MouseEvent)
{
var dx:Number = Cueball.x - mouseX;
var dy:Number = Cueball.y - mouseY;
var dist:Number = Math.sqrt(dx * dx + dy * dy);
//Cue.x = dx + Cueball.x;
//Cue.y = dy + Cueball.y;
if (dist > 230)
{
Cue.startx = Cue.x;
Cue.starty = Cue.y;
Cue.addEventListener(Event.ENTER_FRAME,FinishShoot);
}
}
public function FinishShoot(event:Event)
{
var dx:Number = Cueball.x - Cue.x;
var dy:Number = Cueball.y - Cue.y;
var dist:Number = Math.sqrt(dx * dx + dy * dy);
if (dist < 230)
{
Cueball.vx = Cue.x - Cue.startx;
Cueball.vy = Cue.y - Cue.starty;
Cue.removeEventListener(Event.ENTER_FRAME,FinishShoot);
}
}
You could add a Boolean isShooting for instance. In your MOUSE_DOWN handler you can set it to true and within the aimCue you can check wether it's true or not. When your done shooting, you can set it to false again.
For the logic to move your cue you could use something like this: (don't forget to remove the stage listener when you're finished shooting)