playcanvas / playcanvas-tween

A tween library for PlayCanvas
MIT License
59 stars 45 forks source link

Tweens are not working when playcanvas is in background #36

Open Arjunxxxl opened 1 year ago

Arjunxxxl commented 1 year ago

We are making a game in which we are updating entity's position and rotations using tween library using the following code.

//for position
let moveT = this.entity.tween(this.entity.getLocalPosition()).to({x: finalPos.x, y: finalPos.y, z: finalPos.z}, isInstant ? 0 : this.moveDuration, pc.CubicInOut)
                    .delay(isDelayed ? this.moveDelay * cardNumber : 0)
                    .on('complete', function(){
                    });

    moveT.start();

//for rotation
this.entity.tween(this.entity.getLocalEulerAngles()).rotate(this.frontrotation, rotationDuration, pc.Linear)
            .start()
            .on('update', function (dt) {

            })
            .on('complete', function () {
            });

And the both of the functions are executed after a settimeout call. Now the issue is when we are putting playcanvas in background, the tweens are not working. and when the playcanavas is moved to foreground only the rotation tween works and position tween doesn't works. Can anyone help me out here? thanks.

yaustar commented 1 year ago

Now the issue is when we are putting playcanvas in background, the tweens are not working.

PlayCanvas uses the animation frame callback for 'frame updates' and tween manager is dependent on the engine's update loop.

When the tab is in the background, the browser callback for animation is not called by the browser for the tab so no engine update is done while the tab is in the background.

and when the playcanavas is moved to foreground only the rotation tween works and position tween doesn't works.

Surprised that it isn't consistent. Can you provide a simple example project that could be investigated please?