2012-05-23 19 views
0

我试图旋转一个固定的数量的影片剪辑以度它有我平滑等,所以mc.rotate(int)出来。旋转movieclip一个固定的od度的顺利

目前我有这里面无限旋转:

public function wheelSpinning() : void 
    { 
     addEventListener(Event.ENTER_FRAME, startSpin); 
    } 

    public function startSpin(event:Event):void 
    { 
     mc.rotation+=1; 
    } 

任何人都可以点我这个方向是正确的?第一次这样做,我很难过。谷歌fu返回结果混杂,我担心我使用错误的关键字。

回答

3

使用来自Greensock.com的TweenMax库。它有一个非常有用的方法/插件:shortRotation,它可以在最短的方向自动旋转(当物体旋转180度时非常有用)。

TweenMax.to(mc, 1, {shortRotation:{rotation:270}}); 

就是这样。

我不会使用Flash的Tween类 - 它们效率不高。

+0

对于shortRotation方法+1。它在许多情况下是一个很好的时间。 –

0

解决方案1: 一旦您达到您想要的旋转角度,请移除该事件。

public function startSpin(event:Event):void 
{ 
    if(mc.rotation == someValue) 
    { 
     removeEventListener(Event.ENTER_FRAME, startSpin); 
    } 
    else 
     mc.rotation+=1; 
} 

解决方案2: 使用闪光补间! http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/transitions/Tween.html

解决方案3: 使用第三方补间库。我使用Tweener http://hosted.zeh.com.br/tweener/docs/en-us/

0

你可以使用一个基本easing让事情顺利:

private var degrees:Number = 2; // increase rotation by 2 
private var easing:Number = .5; // easing value 
private var finalDegree:Number = 90; // Degree the rotation will iterate to 

... 

public function wheelSpinning() : void 
{ 
    addEventListener(Event.ENTER_FRAME, startSpin); 
} 

public function startSpin(evt:Event):void 
{ 
    var c:Number = mc.rotation + degrees * easing; 

    if (c >= finalDegree) 
    { 
     /* Prevent the rotation from being greater than the 
      finalDegree value and remove the event listener */ 
     mc.rotation = finalDegree; 
     removeEventListener(Event.ENTER_FRAME, startSpin); 
    } 
    else 
    { 
     /* Apply the easing to the rotation */ 
     mc.rotation = c; 
    } 
} 

播放与价值观,并找出适合您需要的人。 如果你正在学习AS3,我建议你避免使用库来动画和自己写一切。虽然这些图书馆的底线比我在这里介绍的要复杂得多,但您仍对所发生的事情有基本的了解。
否则,最好使用封装所有这些有趣数学的图书馆,只是担心你的应用程序/游戏的逻辑。你可以在那里找到很多库,如GTweenGreensock

希望它有帮助。