mirror of
https://github.com/Xevion/Pac-Man.git
synced 2026-01-31 12:25:04 -06:00
Add stop_game and restart_game FFI functions to properly pause/resume the game loop during page transitions, preventing resource leaks and audio issues when navigating between pages
15 lines
529 B
TypeScript
15 lines
529 B
TypeScript
import type { OnPageTransitionStartAsync } from "vike/types";
|
|
import { getPacmanWindow } from "@/lib/pacman";
|
|
|
|
export const onPageTransitionStart: OnPageTransitionStartAsync = async () => {
|
|
console.log("Page transition start");
|
|
document.querySelector("body")?.classList.add("page-is-transitioning");
|
|
|
|
// Stop the game loop when navigating away from the game page
|
|
const win = getPacmanWindow();
|
|
if (win.Module?._stop_game) {
|
|
console.log("Stopping game loop for page transition");
|
|
win.Module._stop_game();
|
|
}
|
|
};
|