如何使用greensock补间as3中的多个对象?
how to tween a number of objects in as3 using greensock?
我需要制作一个动画,其中有许多物体(大约 500 个)从左向右飞行,具有不同的延迟、持续时间和目的地。
但是,一旦所有对象都已到达目的地,我需要 运行 另一个函数。
每次当一个物体完成飞行时,我都尝试进行循环检查。即:
...
for(var i:int = 0; i < objs.length; i++)
Tweenlite.to(obj[i], duration, {delay:delay, x:destination.x, y:destination.y, onComplete:CheckAllComplete});
...
private function CheckAllComplete():void
{
for(var i:int =0 ;i < objs.length; i++)
{
if(Tweenlite.getTweensOf(obj[i]).length > 0)
return;
}
... // if all the flights complete
}
但我认为它非常笨重,更不适合 CPU。
所以,我的问题是,如何将所有对象视为一个补间并仅添加 onComplete
来解决问题?
类似于:
var tween:*;
for(...)
tween.add(obj[i], duration, {...});
tween.onComplete = CompleteCallback;
基于您自己的代码(我没有检查是否有效或有任何错误)
private var tweenObjectsIndex:uint = 0;
private var numObjects:uint = objs.length;
for(var i:int = 0; i < numObjects:uint; i++)
Tweenlite.to(obj[i], duration, {delay:delay, x:destination.x, y:destination.y, onComplete:CheckAllComplete});
private function CheckAllComplete():void
{
tweenObjectsIndex++;
// if all the flights complete
if(tweenObjectsIndex == numObjects) // do something
}
我需要制作一个动画,其中有许多物体(大约 500 个)从左向右飞行,具有不同的延迟、持续时间和目的地。 但是,一旦所有对象都已到达目的地,我需要 运行 另一个函数。
每次当一个物体完成飞行时,我都尝试进行循环检查。即:
...
for(var i:int = 0; i < objs.length; i++)
Tweenlite.to(obj[i], duration, {delay:delay, x:destination.x, y:destination.y, onComplete:CheckAllComplete});
...
private function CheckAllComplete():void
{
for(var i:int =0 ;i < objs.length; i++)
{
if(Tweenlite.getTweensOf(obj[i]).length > 0)
return;
}
... // if all the flights complete
}
但我认为它非常笨重,更不适合 CPU。
所以,我的问题是,如何将所有对象视为一个补间并仅添加 onComplete
来解决问题?
类似于:
var tween:*;
for(...)
tween.add(obj[i], duration, {...});
tween.onComplete = CompleteCallback;
基于您自己的代码(我没有检查是否有效或有任何错误)
private var tweenObjectsIndex:uint = 0;
private var numObjects:uint = objs.length;
for(var i:int = 0; i < numObjects:uint; i++)
Tweenlite.to(obj[i], duration, {delay:delay, x:destination.x, y:destination.y, onComplete:CheckAllComplete});
private function CheckAllComplete():void
{
tweenObjectsIndex++;
// if all the flights complete
if(tweenObjectsIndex == numObjects) // do something
}