So I went to flip to a tab to study some threeJS code last night & for some reason when I switched to that tab then back to the other tab, my demo acts up THEN goes back to normal. Is there a way to pause my simulation until the tab is back in focus? If so, how?
I would also like the function to RETURN whether or not the tab is in focus so I can store it for later use.
Not sure about the pausing part but window.onblur and window.onfocus are what I use to find out whether the user is actually interacting with my project. Keep in mind though that even opening dev tools and typing something in the console will count as the project being out of focus.
But do you even need to do that anymore? Unless I misunderstood the question, you want to be able to check whether or not the tab is in focus. If so, can’t you just check the value of document.hidden from anywhere within your code?
So here’s what I did, I created a “this.__PauseDemo ( __isPaused ) { }” function library which simply checks whether or not visibilityChange is true or false & returns either true or false based on that. Problem is, it’s not returning the value in the javascript object that it’s supposed to.
my demo acts up THEN goes back to normal. Is there a way to pause my simulation until the tab is back in focus?
A simple approach here is to check the frame time, and if it’s bigger than, say, 500ms, skip animation for that frame. That prevents jumps when switching windows.