开发者

Looping DisplayObject animation

开发者 https://www.devze.com 2023-01-18 11:25 出处:网络
I have multiple object doing random开发者_如何学JAVA movement with random speed. i wanted to repeat the 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

精彩评论

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

关注公众号