2

Like those "idle games" (Candy Box, Cookie Clicker) which you're meant to leave open in your browser as you do other things. It must be simple, but I haven't been able to find a straight answer.

As it is, all the activity in my game freezes when the tab is changed or window minimized, and I want it to continue regardless of whether the window is in focus or not. How would I do this?

edit: another answer had this jQuery solution:

$(window).blur(function(){
  //your code here
});
$(window).focus(function(){
  //your code
});

but I'm still not sure what I would put there in order to keep the game loop running when out of focus.

user2493615
  • 317
  • 1
  • 8
  • You might want to take a look at [this answer](http://stackoverflow.com/a/1060034/2476755) and this page from [W3C on page visibility](http://www.w3.org/TR/page-visibility/). – royhowie May 03 '14 at 07:27
  • 1
    How are you scheduling timer events in your game? `requestAnimationFrame` is specifically designed not to send events when it would be useless to do so (like when the window is completely obscured or minimized), but `setTimeout` should work in all circumstances, although browsers often throttle it when in the background. – icktoofay May 03 '14 at 07:36
  • I am using `requestAnimationFrame`. I am really a beginner and I don't know how to go about changing this. – user2493615 May 03 '14 at 07:45

0 Answers0