我试图让提示在 MOUSE_DOWN 事件中停止旋转,但继续将 mouseX 和 mouseY 的距离添加到提示与 cueball 的距离。换句话说,为了使球杆沿着线滑动,球杆的目标是向下。
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);
}
}