Skip to content

Commit

Permalink
fixes #638
Browse files Browse the repository at this point in the history
ok hopefully this doesn't break puzzlescript anywhere! I've checked online to see how reliable "visibilitychange" is and it seems to be generally trusted. I've checked on chrome, firefox, and edge on my pc.

I'm going to update the site right away. If anyone notices any problems, lemme know and I'll fix it asap (i worry about the awake event not getting reliably called and the game just never updating again).  (there are other less-likely-to-outright-break-if-browsers-do-things-that-they-shouldn't ways of doing this that don't give as extreme power savings. )
  • Loading branch information
increpare committed Jul 29, 2021
1 parent 60fbab2 commit 95b7086
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/js/inputoutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,24 @@ function update() {
}
}

var looping=false;
// Lights, camera…function!
setInterval(function() {
update();
}, deltatime);
var loop = function(){
looping=true;
update();
if (document.visibilityState==='hidden'){
looping=false;
return;
};
setTimeout(loop,deltatime);
}

document.addEventListener('visibilitychange', function logData() {
if (document.visibilityState === 'visible') {
if (looping===false){
loop();
}
}
});

loop();

0 comments on commit 95b7086

Please sign in to comment.