我必须制作横幅广告(swf)。所以我在中间有一个圆形物体,当你在右侧移动鼠标时,我需要从左向右开始旋转,当你在左侧移动鼠标时,我需要从右向左开始旋转。有任何想法吗?谢谢!
答案 0 :(得分:1)
有很多方法可以做到这一点,但首先尝试一下,看看它是否正在寻找:
private var rotationStep = .25;
private var newX:int;
private var oldX:int;
public Main():void {
// Initialization of your stuff
// When ready add this to track the mouse
this.stage.addEventListener(MouseEvent.MOUSE_MOVE,followMouse);
}
private function followMouse(e:MouseEvent):void {
if(this.newX > this.oldX) {
this.rotate(1);
} else {
this.rotate(-1);
}
this.oldX = this.newX;
}
private function rotate(dir:int):void {
// rotate ball based on direction
this.ball.rotoationZ += this.rotationStep*dir;
}
记住旋转是以弧度为单位,而不是度数