循环显示对象动画

发布于 2024-09-25 19:44:10 字数 264 浏览 1 评论 0 原文

我有多个对象以随机速度进行随机移动。我想重复动画。

我尝试使用 onComplete 在动画结束后重新启动每个对象,但如何将其专门定位到该对象?目前其溢出

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

I have multiple object doing random 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)});
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流星番茄 2024-10-02 19:44:10

当您为 onComplete 设置回调时,您只需传递函数本身即可。通过设置onComplete: lineAnimation(e),它会一遍又一遍地执行lineAnimation。当您需要传递参数时,您可以使用匿名函数进行回调,如下所示:

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

另外,由于您使用的是 TweenLite,您可能需要查看 TweenMax 具有内置循环功能,因此您可以执行如下操作:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文