-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayer.js
More file actions
40 lines (38 loc) · 1.24 KB
/
layer.js
File metadata and controls
40 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export class MapLayer {
constructor(game, speedModifier) {
this.game = game;
this.speedModifier = speedModifier || 1;
this.x = this.y = 0;
this.image;
this.width;
this.height;
this.imageIndex;
this.dimensions;
this.speedX = this.speedY = 0;
}
setWorld(world) {
this.image = world;
//set x and y to 0
this.x = this.y = 0;
this.imageIndex = this.game.assetManager.images.indexOf(this.image);
this.dimensions = this.game.assetManager.imageDimensions[this.imageIndex];
this.width = this.dimensions[0];
this.height = this.dimensions[1];
}
render(ctx) {
ctx.drawImage(
this.image,
(-this.game.camera.viewportX * this.speedModifier) + this.x,
(-this.game.camera.viewportY) + this.y,
this.game.camera.worldWidth,
this.game.camera.worldHeight
);
ctx.drawImage(
this.image,
-this.game.camera.viewportX * this.speedModifier + this.game.camera.worldWidth,
-this.game.camera.viewportY + this.y,
this.game.camera.worldWidth,
this.game.camera.worldHeight
);
}
}