3

I'm making a HTML game with 'Egret', but when ever I switch to other tab, my game just pause automatically.

Is there any solution to prevent game pause?

Picture

Community
  • 1
  • 1
Samuel Lin
  • 33
  • 3
  • Some more information would help. Is Egret a game engine? Google did not reveal much. Also, some code that you think is causing this might help us help you. – Sid Mar 02 '17 at 05:39
  • If you are using js animation [This SO Answer](http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome) can help you out. – RRajani Mar 02 '17 at 05:42
  • Yes, Egret is a game engine, using typescript. I think Google didn't reveal much is because Egret is made by Chinese. – Samuel Lin Mar 02 '17 at 05:48
  • I have done some research about this issue. Some game engine had provide this function, like Phaser engine. (http://www.html5gamedevs.com/topic/10847-gamestagedisablevisibilitychange-not-working/) – Samuel Lin Mar 02 '17 at 05:52
  • try to add some code – Sagar V Mar 02 '17 at 05:52
  • I just wondering, why Facebook game can keep running, even in other tab. – Samuel Lin Mar 02 '17 at 05:57

1 Answers1

4

Most of the game's tick is based on the requestAnimationFrame. And this function is based on the browser's repaint. If you switch to another tab, the repaint is stop, so the requestAnimationFrame stop.

If you really need your game run after switch to another tab, use the setInterval as your game's tick with time 1000/60.

But this is not so performance as the requestAnimationFrame.

shuizhongyuemin
  • 559
  • 5
  • 11