Continue running game on background

Hi guys,

Our game needs to run in the background (when the browser tab is inactive) as there are some animations in the middle, i did see a few posts regarding this, but they were more than 12 months old. Has there been any additions to the engine, like the “Run in background” option for Unity?

The TLDR is that you are limited by what the browser allows you to do.

PlayCanvas engine will update for every animation frame event the browser fires. If the browser doesn’t fire these events (like when the tab is inactive), then the engine will not update.

You can try to customise the engine to use something like setInterval instead of requestAnimationFrame but even then, the browser may throttle or limit these if the tab is in the background.

What I would consider here is detect when that tab goes inactive and back to active, measure that time and advance your game updates/animation/state of the game forward by that amount.

It’s not that trivial to do so you have to do you own research on how to architect this in your game

1 Like

You can play endless empty sound and web socket work so that your page does not lose priority and goes to sleep.