From dda6a008ceb707d38f24ac0f987a1328f48f244b Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 29 Sep 2023 13:21:01 +0500 Subject: [PATCH] Gravity example: Pause when browser is not active --- examples/gravity/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/gravity/index.js b/examples/gravity/index.js index 9f4481f..9c0283f 100644 --- a/examples/gravity/index.js +++ b/examples/gravity/index.js @@ -207,6 +207,16 @@ function calculateForce(p1, p2, g, out) { } } +document.addEventListener("visibilitychange", function () { + if (document.hidden) { + BootstrapInstance.pause(); + } else { + BootstrapInstance.play(); + } + + console.log(performance.now(), BootstrapInstance.state); +}); + // noinspection InfiniteLoopJS while (true) { await BootstrapInstance.requestPhysicsFrame(gravityStep);