开发者

Easing and timer event AS3

My meter looks great and the needle rotates in a loop. How do I add easing to it?

The meter is built from a timer event. I want the needle to bounce at the end. Rather than just adding a variable, I need some control of when it happens so I can adjust it with the animation.

alt text http://www.ashcraftband.com/myspace/videodnd/icon8.jpg

WORKING CODE "Thxs to member"

var timer:Timer = new Timer(20, 30);//tick 200, 36<br>

timer.addEventListener(TimerEvent.TIMER, onTimer); 
timer.addEventListener(TimerEvent.TIMER_COMPLETE, startAgain); 

timer.start(); 

function startAgain($evt:TimerEvent):void { 
    timer.reset(); 
    timer.start(); 
} 

function onTimer($evt:TimerEvent):void { 
    watch.hand.rotation = 30 + timer.currentCount;//tick 5 
} 

FAILED ATTEMPT "needle's crazy, it's just suppose to bounce"

//the "tick" may mess up the effect

import fl.transitions.Tween;
import fl.transitions.easing.*;
var timer:Timer = new Timer(20, 30);//tick 200, 36
  var startValue:Number = watch.hand.rotation;
  var finishValue:Number = 33;//400
  var duration:Number = 222;//3
  var myTween:Tween = new Tween(watch.hand, "rotation", Elastic.easeOut, startValue, finishValue, duration, false);//true
  myTween.looping = true;
timer.addEventListener(TimerEvent.TIMER, onTimer); 
timer.addEventListener(TimerEvent.TIMER_COMPLETE, startAgain); 

timer.start(); 

function startAgain($evt:TimerEvent):void { 
    timer.reset(); 
    timer.start(); 
} 
function onTimer($evt:TimerEvent):void { 
    watch.hand.rotation = 30 + timer.currentCount;//tick 5
 //watch.x =+ 66;

} 

EXPERIMENT

My project will requires a higher understanding of timer events and tweening. If I can get this animation to do stuff, I think I can better understand how to pass function ca开发者_如何学编程lls and set up events.


As @pfunc mentioned, this is going to be far easier to accomplish with a third party tweening library. It can be done with fl.transitions.Tween, but the chaining of tweens and onComplete handling is less than desirable.

As mentioned, check out one of these:

GTween

TweenLite

Tweener

All of these 3 have a very similar API (which is far better than Flash's built-in Tween - IMHO)

When I helped out with your original question about the Timer class, I did not realize that this is what you wanted to do. The Timer class is not a suitable choice for this problem as it is intended for events to be handled on consistent basis.


I would use another tweening engine for this. Check out tweener or gtween. Makes things easier for animating and you can call functions when a tween has finished animating. You can create custom tweens and adjust how much bounce you want. There might be a way to do this with flash's built in tweening engine, but not sure how.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜