HTML: How to prevent pausing the game when it's losing the focus?

Hi! The game i work on currently is an idle/incremental game. In a browser, for this type of games it is essential that it continues to run in the background while the player does other things. But whenever i switch to another tab or application, the game is automatically paused.

Is there a way to change that?

Do you actually need the game to run or is it enough to know the amount of time elapsed since the window lost focus and “fast forward” that amount of time?

Measuring the elapsed time to fast forward would be my backup solution.

But as far as i observed similar games, they seem to continue to run normally when losing focus and only fast-forward when their tab is closed and opened again later. This would be my preferred behaviour.

I would say that this is exactly how all idle games are doing it.
You must save the time for the pause. This also allows the idle/incremental process to be calculated even if you close down the app which happens a lot.
iOS doesn’t allow any code of this kind to run in the background and if Defold did run it, iOS would shut down the app.
Edit: Ah sry, for some reason I thought it was for mobile. Don’t know about browser behaviour. I guess it stops all code and hide right now as it is the most multiplatform compatible way of handling it.

1 Like

Thank you. I feared it would be a compatibility reason why the engine pauses execution. I guess i’ll have to do the time-saving thing then.

Simulating it is better. Another way you can deal with this is to give them a free boost while the game is not active for the amount of time that the game is not running. Then they can control the boost (feels rewarding), it makes them want to come back to the game (re-engagement). You can have a max boost time too so they can’t forget about it for days and have a big boost.

3 Likes