Skip to content

Commit 369c9e5

Browse files
committed
fix broken img
1 parent 512ac6f commit 369c9e5

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/JSTools.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -844,14 +844,16 @@ class JSImage extends Control {
844844
draw() {
845845
const ctx = (window as any).globals.canvas.getContext('2d') as CanvasRenderingContext2D;
846846

847-
ctx.save();
848-
ctx.scale(this.scale, this.scale)
849-
ctx.drawImage(
850-
this.img,
851-
this.x / this.scale - (this.xAlign === 'middle' ? this.img.width / 2 : 0),
852-
this.y / this.scale - (this.yAlign === "middle" ? this.img.height / 2 : 0)
853-
);
854-
ctx.restore();
847+
if (this.img.complete && this.img.naturalWidth > 0 && this.img.naturalHeight > 0) {
848+
ctx.save();
849+
ctx.scale(this.scale, this.scale)
850+
ctx.drawImage(
851+
this.img,
852+
this.x / this.scale - (this.xAlign === 'middle' ? this.img.width / 2 : 0),
853+
this.y / this.scale - (this.yAlign === "middle" ? this.img.height / 2 : 0)
854+
);
855+
ctx.restore();
856+
}
855857
}
856858
}
857859

src/Monopoly/Main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ startWindow.container.welcomeText.updateLanguage = function(){this.text="Bem vin
3434
startWindow.container.txt2 = new Label(650, 550+10, "Welcome! 😀", "center");
3535
startWindow.container.txt2.updateLanguage = function(){this.text=" !"};
3636

37-
startWindow.container.img = new JSImage(650, 300, "/resources/HTML5.png", "middle", "middle");
37+
startWindow.container.img = new JSImage(650, 300, "resources/HTML5.png", "middle", "middle");
3838
startWindow.container.img.scale = 0.3;
3939

40-
startWindow.container.img2 = new JSImage(650, 550, "/resources/Monopoly.svg", "middle", "middle");
40+
startWindow.container.img2 = new JSImage(650, 550, "resources/Monopoly.svg", "middle", "middle");
4141
startWindow.container.img2.scale = 0.3;
4242

4343
game.container.board = new Board(0, 0);

0 commit comments

Comments
 (0)