JAA Posted July 23, 2017 Share Posted July 23, 2017 I want to run myPixi.ticker.stop() when the window loses focus in any way, eg minimize, click a different tab or even closing the window. Q: Is there a javascript event that covers all the possibilities? Q2: Is there a javascript event that covers all possible methods of a window regaining focus, eg a return from minimize, reclicking the tab etc? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 23, 2017 Share Posted July 23, 2017 That's how RAF (requestAnimationFrame) works, you dont have to do anything. Then there's different question: how to calculate something when window is minimized? Add extra setInterval with stuff you need to calculate somewhere,m that checks if last frame was too long ago. Quote Link to comment Share on other sites More sharing options...
themoonrat Posted July 24, 2017 Share Posted July 24, 2017 Indeed, RequestAnimationFrame will stop when the the browser things it's not worth rendering anything to the window because it's minimized. There is however the Page Visibility API to detect this event (https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API) - This could be useful to pause sounds when you know the game has become not visible, or to put up a pause menu if you wish Quote Link to comment Share on other sites More sharing options...
JAA Posted July 24, 2017 Author Share Posted July 24, 2017 Thanks @ivan.popelyshev and @themoonrat. Your combined answers where exactly the info I was looking for. ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.