Screen Update when my browser hidden

Screen Update when my browser hidden
0

#1

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


#2

What do you mean by Screen CC not update. ?


#3

Yes. Update function not working too.


#4

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


#5

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


#6

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.


#7

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


#8

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 () {}

#9

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


#10

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


#11

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.


#12

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


#13

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


#14

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.


#15

The problem has been solved here : youtube