diff --git a/src/pages/Index.jsx b/src/pages/Index.jsx index 31ba010..71e0a20 100644 --- a/src/pages/Index.jsx +++ b/src/pages/Index.jsx @@ -82,11 +82,13 @@ const Index = () => { } }; + let animationFrameId; + const gameLoop = () => { if (isGameRunning) { draw(); update(); - requestAnimationFrame(gameLoop); + animationFrameId = requestAnimationFrame(gameLoop); } }; @@ -117,6 +119,7 @@ const Index = () => { return () => { window.removeEventListener("keydown", handleKeyDown); + cancelAnimationFrame(animationFrameId); }; }, [isGameRunning]);