Fix pause to freeze physics and stop extra runner loops

This commit is contained in:
Daddy32
2025-12-12 13:09:27 +01:00
parent 6fc2cbbb59
commit f482cafb2f

14
main.js
View File

@@ -24,11 +24,11 @@
id: "scene1", id: "scene1",
name: "Balanced (default)", name: "Balanced (default)",
config: { config: {
gravity: 1, gravity: 0.78,
spawnIntervalMs: 520, spawnIntervalMs: 720,
minChain: 3, minChain: 3,
palette: ["#ff595e", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93"], palette: ["#ff595e", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93"],
ballRadius: 18, ballRadius: 38,
}, },
createBodies: (w, h) => [ createBodies: (w, h) => [
Bodies.rectangle(w / 2, h + 40, w, 80, { Bodies.rectangle(w / 2, h + 40, w, 80, {
@@ -282,7 +282,7 @@
isPaused = false; isPaused = false;
resetChainVisuals(); resetChainVisuals();
stopSpawner(); stopSpawner();
Runner.stop(runner); engine.timing.timeScale = 0;
pauseOverlay.classList.remove("visible"); pauseOverlay.classList.remove("visible");
pauseBtn.textContent = "Pause"; pauseBtn.textContent = "Pause";
finalScoreEl.textContent = score; finalScoreEl.textContent = score;
@@ -302,8 +302,8 @@
gameOverEl.classList.remove("visible"); gameOverEl.classList.remove("visible");
pauseOverlay.classList.remove("visible"); pauseOverlay.classList.remove("visible");
pauseBtn.textContent = "Pause"; pauseBtn.textContent = "Pause";
engine.timing.timeScale = 1;
updateHud(); updateHud();
Runner.run(runner, engine);
startSpawner(); startSpawner();
}; };
@@ -321,10 +321,10 @@
if (isPaused) { if (isPaused) {
resetChainVisuals(); resetChainVisuals();
stopSpawner(); stopSpawner();
Runner.stop(runner); engine.timing.timeScale = 0;
} else { } else {
startSpawner(); startSpawner();
Runner.run(runner, engine); engine.timing.timeScale = 1;
} }
}; };