开发者

Looping DisplayObject animation

I have multiple object doing random开发者_如何学JAVA movement with random speed. i wanted to repeat the animation.

I tried to use onComplete to restart each object once the animation end, but how could I specifically target it to that object? Currently its overflow

private function lineAnimation (e:DisplayObject):void
    {
        TweenLite.to (e,randomTime, {x:randomX, onComplete: lineAnimation(e)});
    }


When you set a callback for onComplete, you need to just pass the function itself. By setting onComplete: lineAnimation(e), it is executing lineAnimation again over and over. As you need to pass the parameter, you can use an anonymous function for the callback like so:

private function lineAnimation (e:DisplayObject):void
{
    TweenLite.to(e, randomTime, {x:randomX, onComplete:function():void {lineAnimation(e)}});
}

Also since you are using TweenLite, you may want to check out TweenMax which has looping built-in so you can do something like so:

TweenMax.to(e, randomTime, {x:randomX, repeat:-1}); // -1 repeats indefinitely
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜