im trying to double check how can i be sure that game is not rendered or running when im hiding my tab, is there any reliable way? im trying to log event on the ide logs when the tab of my game is hidden but is not consistent so im sill trying to find a reliable way, does three.j by itself handle that when game is not visible , does it stop running or we need to configure that? if three.js already stop the rendering when tab is hidden is there a way we can add aditional code or logic or hook them into that event so aditional logic not present in the native three.js also stop running?
to manage this, you’d ideally want to use the following in the animation loop, only updating values and rendering when the tab / page is visible…
function animate() {
if (document.visibilityState === "hidden") {
// hidden
}
if (document.visibilityState === "visible") {
// visible
// update variables / animated values
render()
}
}
thanks, after some testing it worked , replace render by requestAnimationFrame and cancelAnimationFrame for stop resume