Jump to content

Pause When Window Not in Focus


Recommended Posts

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?



Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...