Actionscript 3 TweenLite AS3:ease:Linear.easeNone不';行不通
在下面的函数中,我尝试将随机项(由函数generateItem()生成)扔到舞台上,让它们从舞台右侧的外侧移动到舞台左侧的外侧。这很好,但唯一的问题是ease:Linear.easeNone在TweenLite.to函数中不起作用。项目在动画开始时保持快速,在动画结束时保持慢速。代码如下:Actionscript 3 TweenLite AS3:ease:Linear.easeNone不';行不通,actionscript-3,random,timer,easing,gsap,Actionscript 3,Random,Timer,Easing,Gsap,在下面的函数中,我尝试将随机项(由函数generateItem()生成)扔到舞台上,让它们从舞台右侧的外侧移动到舞台左侧的外侧。这很好,但唯一的问题是ease:Linear.easeNone在TweenLite.to函数中不起作用。项目在动画开始时保持快速,在动画结束时保持慢速。代码如下: private function timerHandler(event:TimerEvent):void{ //item handling if(gameTimer.currentCount
private function timerHandler(event:TimerEvent):void{
//item handling
if(gameTimer.currentCount % 4 === 0){
var item:MovieClip = generateItem();
arrItems.push(item);
for each(item in arrItems){
TweenLite.to(item,5,{x:-(item.width - 1), ease:Linear.easeNone});
trace(item + " ----- " + item.x);
if(item.x < -(item.width)){
arrItems.splice(arrItems.indexOf(item),1);
stage.removeChild(item);
}
}
}
私有函数timerHandler(事件:TimerEvent):无效{
//物品处理
如果(gameTimer.currentCount%4==0){
变量项:MovieClip=generateItem();
arrritems.push(项目);
对于每个(项目中的项目){
TweenLite.to(项目5,{x:-(项目宽度-1),ease:Linear.easeNone});
跟踪(项+“----”+项.x);
如果(项目x<-(项目宽度)){
arrItems.拼接(arrItems.indexOf(项目),1);
阶段。移除儿童(项目);
}
}
}
这里发生的事情是,您在中一次又一次地为每个
循环覆盖您的tween。一旦您使用TweenLite为对象设置了tweening动画。要
您不需要为同一对象再次设置它,除非您想使用新tween覆盖它
您看到动画结尾变慢的原因是,对象必须移动距离,直到tweening动画的终点变小(因为它已经覆盖了其中的一部分),但动画的总持续时间仍为5秒。速度=距离/时间,因此相同时间但较短距离=较慢的吐温
您只需移动TweenLite即可解决此问题。要在循环
之外调用,因此只为每个项目设置一个tween。我建议您的代码的另一个改进是使用TweenLite的onComplete
回调函数,以避免在timeH中为每个
循环设置昂贵的andler函数,并仅在tweening完成后删除该项,除非您出于某些其他原因需要遍历所有项,而不仅仅是检查tweening是否已结束
例如:
private function timerHandler(event:TimerEvent):void
{
//item handling
if(gameTimer.currentCount % 4 === 0)
{
var item:MovieClip = generateItem();
arrItems.push(item);
//only call once for each item
TweenLite.to(item,5,{ x:-(item.width - 1),
ease:Linear.easeNone,
onComplete: removeItem,
onCompleteParams:[item]
});
}
}
private function removeItem(item:MovieClip):void
{
arrItems.splice(arrItems.indexOf(item),1);
stage.removeChild(item);
}
希望这有帮助