2008-11-21 126 views
2

随着代码如下,有时子控件正确地完成他们的动画,有时他们停在随机的地方在中间。他们为什么不正确工作?为什么补间会随机停止?

var t:Tween; 
t = new Tween(child1,"x",Elastic.easeOut,0,100,2,true); 
t = new Tween(child1,"y", Elastic.easeOut,0,100,2,true); 
t = new Tween(child2,"x",Strong.easeOut,300,400,1,true); 
t = new Tween(child2,"y", Strong.easeOut,300,400,1,true); 

回答

1

您也可以在您的类的范围内创建一个数组,然后将补间推送到该数组上。虽然这可能会导致数组中的补间永远不会收集垃圾,即使它们完成后也是如此,因此您可能希望自己在已知所有补间完成的点上清空阵列。

3

必须将每个补间分配给全局范围内的单独变量。下面的代码具有可靠:

var t1:Tween = new Tween(child1,"x",Elastic.easeOut,0,100,2,true); 
var t2:Tween = new Tween(child1,"y", Elastic.easeOut,0,100,2,true); 
var t3:Tween = new Tween(child2,"x",Strong.easeOut,300,400,1,true); 
var t4:Tween = new Tween(child2,"y", Strong.easeOut,300,400,1,true); 

这样看来,当重新使用的变量,即不再被引用的补间可能会被垃圾收集或以其他方式在其工作的中间暂停。

如果您使用单独的变量,但在函数的本地范围而不是您的框架的全局范围内声明它们,则会出现同样的问题。

4

此外,请尝试使用免费/开放源代码补间引擎,而不是使用Flash打包的引擎。两种非常流行的是TweenLiteTweener。它们提供更高的性能和更多的功能/选项。