improve page unloading

This commit is contained in:
LabyStudio
2022-05-13 21:41:59 +02:00
parent 22cd91e99b
commit 02497c2d36
3 changed files with 12 additions and 5 deletions
+7 -2
View File
@@ -48,5 +48,10 @@ class Start {
}
}
// Launch game
new Start().launch("canvas-container");
// Listen on history back
window.addEventListener('pageshow', function (event) {
// Launch game
if (!window.app || !window.app.running) {
new Start().launch("canvas-container");
}
});
+4 -2
View File
@@ -127,8 +127,6 @@ export default class Minecraft {
if (this.running) {
this.requestNextFrame();
this.onLoop();
} else {
this.window.close();
}
});
}
@@ -372,10 +370,14 @@ export default class Minecraft {
}
stop() {
if (this.currentScreen !== null) {
this.currentScreen.onClose();
}
this.running = false;
this.worldRenderer.reset();
this.itemRenderer.reset();
this.screenRenderer.reset();
this.window.close();
}
getThreeTexture(id) {
@@ -47,7 +47,7 @@ export default class ScreenRenderer {
}
reset() {
this.stack2d.clearRect(0, 0, this.window.width, this.window.height);
this.stack2d.clearRect(0, 0, this.window.canvas2d.width, this.window.canvas2d.height);
}
}