kittykatattack / smoothie

Ultra-smooth sprite animation for Pixi using true delta-time interpolation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

update() function is not executed when the tab is switched in Chrome/Firefox

gkakasevski opened this issue · comments

I put the game logic in update() function, but when I change the tab in Google Chrome and Firefox, the code in update() is not executing.

Hello,

Does it execute when you switch back to your tab running Smoothie?

Chrome suspends requestAnimationFrame on closed tabs as an energy saving feature, so that's expected behaviour.

Yes, the update() function continue. But as I understand your project, the update function should run in background even if requestAnimationFrame is stopped, because game logic should be put here (for example, for multiplayer game or in game in which something is changed even if player switch between tabs). As you describe in documentation:

The last option, update is extremely important! It's the name of a function that will contain all of your game or application logic. Smoothie will run the function that you supply in a loop, at whatever frame rate you've specified. This is your game or application logic loop.

As I know "game or application logic loop" should execute non-stop. Sorry if I don't understand purpose of your library correctly. If update() stops, then I should implement another function for game logic which should execute in intervals (maybe with setInterval() or another plugin).

Yes, all the browsers suspend calls to requestAnimationFrame when browser tabs are changed.
This is great feature because it prevents unnecessary CPU usage when pages are not being viewed - it prevents the browser from slowing down and hanging.
If you are creating a multiuser game, your game logic should be running on your server, not in the browser.
In that case, don't use Smoothie to update your game logic loop - get that information from the sever and just use Smoothie's update loop to synchronize that data with your display logic.

I understand you completely. Tnx

Glad to help, thanks for asking the question 😄