Up-in-the-Air – commitdiff

You can use Git to clone the repository via the web URL. Download snapshot (zip)
Pause game if scrolled out of view
authorJulian Fietkau <git@fietkau.software>
Sun, 22 Sep 2024 23:07:19 +0000 (01:07 +0200)
committerJulian Fietkau <git@fietkau.software>
Sun, 22 Sep 2024 23:07:19 +0000 (01:07 +0200)
main.js

diff --git a/main.js b/main.js
index 8ec743e655f04aeb250cbf17ad2d8b716914852d..c6df32a7f05ca8d530ffec69b2be38aebf72ce22 100644 (file)
--- a/main.js
+++ b/main.js
@@ -673,6 +673,15 @@ game.ui.root.style.fontSize = (game.ui.root.clientWidth / 50) + 'px';
 window.addEventListener('resize', () => {
   game.ui.root.style.fontSize = (game.ui.root.clientWidth / 50) + 'px';
 });
+window.addEventListener('scroll', () => {
+  let bbox = game.ui.root.querySelector('canvas').getBoundingClientRect();
+  if(game.ui.currentPage != 'gameplay') {
+    return;
+  }
+  if(bbox.bottom < -100 || bbox.top - bbox.height > 100 || bbox.left + bbox.width < -100 || bbox.left - window.innerWidth > 100) {
+    game.ui.moveToPage('pause', true);
+  }
+});
 window.addEventListener('blur', () => {
   if(game.ui.currentPage == 'gameplay') {
     game.ui.moveToPage('pause', true);