Page switches, particleSystem reset

When the page switches,particleSystem seems to be reset,

use visibilitychange paused , doesn’t resolve the issue

document.addEventListener("visibilitychange", () => {
            if (document.hidden) {
                this.scene.particleSystems.forEach(ps => ps.paused = true);
            } else {
                this.scene.particleSystems.forEach(ps => ps.paused = false);
            }
 });

Can you try with this:

window.addEventListener("blur", () => {
  console.log("Window lost focus");
});

window.addEventListener("focus", () => {
  console.log("Window gained focus");
});

when switch the chrome tab,issue still exists

ok the best way in your case is to do this:

engine._deterministicLockstep = true;

This is a hack for the PG. In your code, simply create your engine with this:

this.engine = new BABYLON.Engine(theCanvas, true, {
  deterministicLockstep: true
});
2 Likes

Thanks, this fixed the tab switching problem!
But I noticed the particles move faster now.
I get the general reason, but how can I keep the particle speed the same as 60 FPS when running at higher frame rates?
In 170FPS it very fast

By default the timestep is 1/60 but you can control it with engine._timeStep

You could try using Animation Ratio

engine._timeStep has no effect on particles …

Could you please be more detailed? particleSystem has no “Animation Ratio” properties

Here we are:

Babylon.js Playground

I overloaded scene.getAnimationRatio so you can control the speed when tab is switching

1 Like