aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-12-29 00:03:45 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-12-29 00:03:45 +0000
commit72b0ebea8bbeaf895343284b990e1643ba540f6e (patch)
tree6be981a991e61cfaf05bad8bda98fb03f5802551
parentcd83ca3058dac4caa8bb214a244fa45fbb75488c (diff)
downloadjs-canvas-2023-72b0ebea8bbeaf895343284b990e1643ba540f6e.tar.gz
js-canvas-2023-72b0ebea8bbeaf895343284b990e1643ba540f6e.zip
Clear canvas, preserve state
-rw-r--r--js/game.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/js/game.js b/js/game.js
index f39a6d1..6ed44bd 100644
--- a/js/game.js
+++ b/js/game.js
@@ -163,6 +163,9 @@ class Game {
let ctx = this.canvas.getContext("2d");
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
+ ctx.save();
+
if (this.loadingError == true) {
ctx.fillStyle = "rgb(255, 128, 128)";
ctx.font = "caption";
@@ -180,6 +183,8 @@ class Game {
Math.floor(ctx.canvas.resSize * (ctx.canvas.width - Math.floor(ctx.canvas.width * 0.2)) / ctx.canvas.dataSize)
), h);
+ ctx.restore();
+
// we don't do this on update because we want
// the progress bar to finish drawing
if (this.resSize == this.dataSize) {