Jump to content

Tweens timeline problem


divers
 Share

Recommended Posts

Hi guys.

I have a little problem with tweens timeline.

I made a demo with my problem: http://zabka229.ct8.pl/

Just click a couple of times where you want to go really fast. Sometimes character is getting extra speed and if you click the same spot multiple times the character stops.

  moveCharacter(path) {

    if (this.movement && this.movement.isPlaying()) {
      this.movement.destroy();
    }

    const tweens = [];
    for (let i = 0; i < path.length - 1; i++) {
      const ex = path[i + 1].x;
      const ey = path[i + 1].y;
      tweens.push({
        targets: this.player,
        x: { value: ex * this.map.tileWidth, duration: 200 },
        y: { value: ey * this.map.tileHeight, duration: 200 }
      });
    }

    this.movement = this.tweens.timeline({
      tweens: tweens
    });

  }

I think that I should wait for finishing first tween in old timeline and then create new one, but I know how to check which tween is currently playing.

Anyone have idea?

 

Link to comment
Share on other sites

So I figured it on my own, here's what I did to detect current tween:

    if (this.movement && this.movement.isPlaying()) {
      const progress = this.movement.elapsed;
      const currentTweenIndex = this.movement.data.findIndex(tween => {
        return (tween.calculatedOffset + tween.duration) > progress;
      });

      const currentTween = this.movement.data[currentTweenIndex];

      if (currentTween) {
        currentTween.setCallback('onComplete', () => {
          this.movement.destroy();
          this.findPath(toX, toY);
        }, []);
      }

    }

where this.movement is current timeline.

 

Have a good day!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...