如何在最大/最小角度停止旋转动画片段?

时间:2012-07-02 13:26:59

标签: actionscript rotation

我有一个按钮(减少),当按下按钮时,箭头向左旋转。我需要箭头停在某个角度(大约在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;
} 

1 个答案:

答案 0 :(得分: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;
}