【问题标题】:TweenLite AS3: ease:Linear.easeNone doesn't workTweenLite AS3:ease:Linear.easeNone 不起作用
【发布时间】:2012-11-14 00:52:32
【问题描述】:

在下面的函数中,我尝试将随机项目(由函数 generateItem() 生成)扔到舞台上,并让它们从舞台右侧外侧移动到左侧外侧。这很好用,但唯一的问题是 TweenLite.to 函数中的 ease:Linear.easeNone 不起作用。项目在动画开始时保持快速,在动画结束时保持缓慢。代码如下:

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);
        }
    }
}

【问题讨论】:

    标签: actionscript-3 random timer easing gsap


    【解决方案1】:

    这里发生的事情是您在for each 循环中一次又一次地覆盖补间。使用TweenLite.to 为对象设置补间动画后,您无需为同一个对象再次设置它,除非您想用new tween 覆盖它。

    您看到动画结束变慢的原因是因为对象必须移动到补间动画的最后一点的距离更小(因为它已经覆盖了其中的一部分) ,但动画的总时长仍然是 5 秒。 速度 = 距离/时间,因此时间相同但距离较短 = 补间较慢。

    您只需将TweenLite.to 调用移到loop 之外即可解决此问题,因此将为每个项目设置一个补间。我为您的代码推荐的另一项改进是使用 TweenLite 的 onComplete 回调函数来避免在 timeHandler 函数中代价高昂的 for each 循环,并且仅在补间完成后删除该项目,除非您需要遍历所有项目出于其他原因,而不是仅仅检查补间是否结束。

    例如:

    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);
    }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      • 1970-01-01
      • 2011-02-05
      • 2016-04-27
      • 1970-01-01
      相关资源
      最近更新 更多