光标图像到mouseout上的中心

时间:2009-11-17 07:53:33

标签: flash actionscript-3

我是一个真正的闪光灯noobie,我想知道是否有人可以帮我这个。

我有这个actionsript 3代码,其中光标图像“ball_mc”跟随鼠标的位置稍有延迟:

stage.addEventListener(Event.ENTER_FRAME,followBall);

function followBall(event:Event):void {
var dx:int = ball_mc.x - mouseX;
var dy:int = ball_mc.y - mouseY;
ball_mc.x -= dx / 5;
ball_mc.y -= dy /5;
}

1)如何在mouseout上自动将光标图像返回到舞台中心?截至目前,它仍处于鼠标离开舞台的位置。

2)如何反转鼠标的移动?因此,当我向右移动鼠标时,光标图像会向左移动?当向上移动鼠标时,图像会下降。

舞台为800 x 250像素,以防万一。

2 个答案:

答案 0 :(得分:0)

首先你可以这样做:


stage.addEventListener(MouseEvent.MOUSE_OUT, comeTOCenter);
function comeToCenter(e:MouseEvent):void {
stage.removeEventListener(Event.ENTER_FRAME,followBall);
ball_mc.x = stage.stageWidth / 2;
ball_mc.y = stage.stageHeight / 2;
}

答案 1 :(得分:0)

我认为你想要这样的东西:

import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;

stage.addEventListener(MouseEvent.MOUSE_MOVE, followBall);
stage.addEventListener(Event.MOUSE_LEAVE, cursorOut);

function  followBall(evt:MouseEvent):void  {
 var dx:int = mouseX-stage.stageWidth;
 var dy:int = mouseY-stage.stageHeight;
 ball_mc.x = -dx ;
 ball_mc.y = -dy ;
} 

function cursorOut(evt:Event):void {
 ball_mc.x=stage.stageWidth/2;
 ball_mc.y=stage.stageHeight/2;
}

cursorOut函数和他的EventListner用于第一个问题,而followBall用于第二个问题。