phaser-ce icon indicating copy to clipboard operation
phaser-ce copied to clipboard

Tweens with multiple TweenData in their timelines lag behind tweens with only 1 TweenData in their timelines

Open autobob opened this issue 8 years ago • 1 comments

This Issue is about: A bug in the API (CE 2.7.3 - also seen in Phaser 2.6.2)

https://jsfiddle.net/uua222wh/1/

I'm creating a game that relies on multiple different layers running running synchronised tweens to animate composite sprites. It seems that a tween made up of multiple TweenData (i.e. one created using lots of calls to Tween.to()) will run significantly slower than a tween made up of less TweenData. I've created an example above. The two animations should each take 1000ms to complete, but they rapidly skew out of synch.

Basically it seems that the larger the value of a tweens's timeline.length, the longer the tween takes to animate.

autobob avatar Jan 26 '17 14:01 autobob

It appears that this issue is caused by the TweenData object clamping the dt value to the duration:

(TweenData.js:372) ` if (this.parent.reverse) {

        this.dt -= ms * this.parent.timeScale;

        this.dt = Math.max(this.dt, 0);

    }

    else

    {

        this.dt += ms * this.parent.timeScale;

        this.dt = Math.min(this.dt, this.duration);

    }`

..When the dt value exceeds the duration the remainder needs to be saved and passed on to the next child object.

I've attached a possible fix to the Tween and TweenData objects. It's not entirely tested, YMMV...

tweenData.zip

autobob avatar Jan 26 '17 17:01 autobob