diff --git a/src/box.js b/src/box.js index cf0ce04..bec47d4 100644 --- a/src/box.js +++ b/src/box.js @@ -3,8 +3,6 @@ const MAX_JUMP = 2; const G = 500; const MAX_FRAME = 9; -let img = new Image(); -img.src = "img/griezmann.png" class Box { constructor() { @@ -74,4 +72,6 @@ class Box { } } -Box.texture = img; +Box.texture = new Image(); +Box.texture.src = "img/griezmann.png" + diff --git a/src/platform.js b/src/platform.js index 84c52d6..394fc07 100644 --- a/src/platform.js +++ b/src/platform.js @@ -11,3 +11,6 @@ class Platform { } } + +Platform.texture = new Image(); +Platform.texture.src = "img/grass.png"; diff --git a/src/scene.js b/src/scene.js index ecb660a..ff6634a 100644 --- a/src/scene.js +++ b/src/scene.js @@ -130,7 +130,6 @@ class Scene extends Screen { drawObject(object) { let size = object.size * this.width(); - this.context.fillStyle = 'rgb(0, 0, 0)'; this.context.drawImage( Box.texture, 0, 64 * this.player.frameNumber, 64, 64, @@ -144,16 +143,13 @@ class Scene extends Screen { let width = object.width * this.width(); let height = object.height * this.height(); - this.context.fillStyle = object.color || 'rgb(0, 0, 0)'; - this.context.beginPath(); - - this.context.rect( + this.context.drawImage( + Platform.texture, + 0, 0, 64, 64, (object.x - object.width / 2) * this.width(), (1 - object.y - object.height / 2 + this.cameraHeight) * this.height(), - width, - height, + width, width, ); - this.context.fill(); } drawHud() {