Screen Update when my browser hidden

Hi all,
I’m working with CC. But when i hidden my browser ( Chrome ) or my tab. Screen CC not update.
Do you have any idea for this problem?
Thanks all

What do you mean by Screen CC not update. ?

Yes. Update function not working too.

Sorry, I don’t understand, you mean when your browser is hidden, you game logic stopped ?

Sr about this. This is my steps

  • When i play my game in a tab
  • I select other tab

My game in hidden tab not update

It’s totally normal, chrome or other browsers will stop the JS execution in hidden tab or window, but some of the browsers (like safari mobile) will simply reduce the frame rate when safari is in background.

It’s browsers’ decision and we can do nothing about it.

To simplify the scenario, in Creator, we listen to the visibilitychange event to manually pause and resume the game, but again, some browser don’t even fire this event, so it’s not entirely reliable neither.

As i know. If you using requestAnimationFrame to update game, when hidden tab or window. Js will stop execute.
If using setInterval to update. Js will still work though browser hidden.

My game update real time. I need my game still continuous working. Do you have any suggest for this scenario.

Thanks

If you set your game’s frame rate to any value less than 60, it will run with setTimeout, maybe that’s what you want.

cc.game.setFrameRate(30);

Besides, you may need to overwrite cc.game.pause and cc.game.resume, do it like this:

cc.game.pause = function () {}
cc.game.resume = function () {}

Hello pandamicro , i have same problem , i want to create a realtime multiplayer game. when i use cocos-js 3.8, i already using

cc.game.setFrameRate(30);

on the first try its work well. but after i restart my computer and test my game again. it’s not working again. my game paused when the fps was 30.
i already test in cocos-js 3.11 , after my computer restart and test my game again . its get paused when in other tab

i was set cc.game.setFrameRate(30). But when i hidden my tab, my game not update :expressionless:

You mean when you change tab, it’s still getting paused even if the frame rate is set to 30 ?

In that case, we can’t do much, the execution in inactive tab is very likely to be paused, because the browser don’t like some heavy work in other tab to disturb the active one. I don’t suggest to rely your game logic on it.

A work around could be when your tab become activate again, calculate the time in between, then run your logic based on the time passed.

Current CC in browser use requestAnimationFrame to update game. Do CC have any function to use setInterval or setTimeout to update game,
My game need update real time, not calculate based logic.
Do you have any suggest

You can take a look at _setAnimFrame function implementation, it’s indeed using setTimeout when you set the frame rate other than 60fps.

seem , you’re right . i test my game with google chrome , only 1 tab wasn’t paused. and the other one is completely paused. thx by the way.

The problem has been solved here : youtube

excuse me , would mind tell me how to solve this problem? i also have this now

1 Like