1

我有一个按钮(减少),当按下按钮时,箭头向左旋转。我需要箭头停在某个角度(大约在 8 点钟方向)。

我怎样才能得到箭头的角度,然后阻止它旋转超过这个点(即使用户一直按下按钮)?

这是我的代码:

import flash.display.MovieClip;
import flash.events.MouseEvent; 
import flash.events.Event;

stop();

var rotate = 0;  

decrease.addEventListener(MouseEvent.MOUSE_DOWN, decreasePressed);  
decrease.addEventListener(MouseEvent.MOUSE_UP, removeEnterFrame); 

function decreasePressed(e:MouseEvent):void  
{   
        rotate = -2;
        addEnterFrame();
}

function addEnterFrame():void 
{     
    this.addEventListener(Event.ENTER_FRAME, update); 
}  

function removeEnterFrame(e:MouseEvent):void 
{     
    this.removeEventListener(Event.ENTER_FRAME, update); 
}  

function update(e:Event):void 
{     
    arrow1.rotation += rotate;
} 
4

1 回答 1

0

假设您的箭头是垂直创建的,箭头指向上方,逆时针旋转(如您所做的那样)时的 8 点钟位置大约为 -112 度。因此,您需要在更新方法中添加检查,以确保箭头的旋转未设置为低于 -112 的值:

// May need to adjust this depending on how your arrow is created
var minDegrees = -112;

function update(e:Event):void 
{   
    var position:int = arrow1.rotation + rotate;

    // Check increment of rotation does not take us past our limit
    if (position <= minDegrees) 
         position = minDegrees;

    arrow1.rotation = position;
} 
于 2012-07-02T23:52:16.467 回答