Added texture for platforms

This commit is contained in:
Thomas Forgione 2018-08-21 16:38:06 +02:00
parent 3466fc57ec
commit 735c1f75cb
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
3 changed files with 10 additions and 11 deletions

View File

@ -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"

View File

@ -11,3 +11,6 @@ class Platform {
}
}
Platform.texture = new Image();
Platform.texture.src = "img/grass.png";

View File

@ -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() {