How I can uninit kaplay context? #597
Unanswered
denisshupenka
asked this question in
Q&A
Replies: 1 comment 3 replies
-
At the moment is not possible quit KAPLAY without that hapening. Why do you need remove KAPLAY instance? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm trying to add a small Kaplay game to my react project, the game is in react component, and I init kaplay in a separate file
`import kaplay from "kaplay";
let k = null;
export const initializeKaplay = () => {
if (k !== null) {
return k;
}
k = kaplay({
width: 1920,
height: 1080,
letterbox: true,
background: [0, 0, 0],
global: false,
buttons: {
jump: {
keyboard: ["space"],
mouse: "left",
},
},
touchToMouse: true,
// debug: false,
});
return k;
};
export const getKaplay = () => k;
export const destroyKaplay = () => {
if (k) {
k.destroyAll();
k = null;
const canvas = document.querySelector("canvas");
if (canvas) canvas.remove();
}
};
`
This context used in a different files, and when game component in unmounted, I use destroyKaplay func.
But when I reopen the game, I have a warning, that KAPLAY already initialized, you are calling kaplay() multiple times, it may lead bugs! And the game is not working correctly..
How I can correctly uninit KAPLAY to avoid this.
Beta Was this translation helpful? Give feedback.
All reactions