开发者

How would I fix this glitch in my (TweenMax) tween?

I got this stupid glitch in the linear tween when the birds fly from left to right (i.e. sometimes they freeze).

开发者_如何学PythonLive : http://tli-temp.heroku.com/

Code :

package tli {

  import flash.events.TimerEvent;
  import flash.utils.Timer;
  import com.greensock.TweenMax;
  import com.greensock.easing.Linear;

public class Birds {

    private var birds:Array;

    public function Birds():void {
      birds = TLI.birds as Array;
      var i:uint = 4;
      while (i > 0) { new_bird(i); --i; }
    }

    private function new_bird(nr:uint):void {
      var b:Bird = new Bird();
      b.name = 'Bird nr.' + nr;
      b.scaleX = 0.23;
      b.scaleY = 0.23;
      b.x = -100;

      TLI.stage.addChild(b);

      birds.push(b);

      setTimeout(function():void {  tween_bird( birds[0] ); birds.shift()  }, rndm(5500, 500));
    }

    private function tween_bird(bird:Bird):void {
      bird.x = -100;
      bird.y = rndm(TLI.stage.stageHeight - TLI.sea.height - 80, 50);

      TweenMax.to( bird, rndm(55,35), {
        x: TLI.stage.stageWidth + 100, ease: Linear.easeNone,
        onComplete: tween_bird, onCompleteParams: [bird]
      });
    }

    private function rndm(max:uint, min:uint=0):uint {  return Math.floor( Math.random() * (max-min) ) + min }
}}

Anyone got an idea how I could fix this?


This:

 var t:Timer = new Timer(wait_time, 1);

Creates a timer in the function scope. When the function goes out of scope, the timer becomes a candidate for garbage collection. It's possible the timer is garbage collected and the complete event never fires.

A setTimeout() call is safe, and probably does what you need.

Not sure if that's the problem you're seeing, but it is a problem you probably want to fix.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜