【问题标题】:how to stop a rotating movieclip at max/min angle?如何以最大/最小角度停止旋转动画剪辑?
【发布时间】:2012-07-03 07:59:10
【问题描述】:

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

【问题讨论】:

    标签: actionscript rotation


    【解决方案1】:

    假设您的箭头是垂直创建的,箭头指向上方,逆时针旋转(如您所做的那样)时的 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;
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-01
      • 2011-09-20
      • 2016-02-18
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      相关资源
      最近更新 更多