-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.js
More file actions
32 lines (30 loc) · 927 Bytes
/
Sprite.js
File metadata and controls
32 lines (30 loc) · 927 Bytes
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
class Sprite {
constructor(config) {
this.image = new Image();
this.image.src = config.src;
this.image.onload = () => {
this.isLoaded = true;
};
this.shadow = new Image();
this.shadow.src = "./images/characters/shadow.png";
this.shadow.onload = () => {
this.isShadowLoaded = true;
};
this.useShadow = true;
this.animations = config.animations || {
idleDown: [[0, 0]],
// walkDown: [
// [0,0],[1,0],[2,0],[3,0]
// ],
};
this.currentAnimation = config.currentAnimation || "idleDown";
this.currentAnimationFrame = config.currentAnimationFrame || 0;
this.gameObject = config.gameObject;
}
draw(ctx) {
const x = this.gameObject.x * 16 - 8;
const y = this.gameObject.y * 16 - 18;
this.isShadowLoaded && ctx.drawImage(this.shadow, x, y);
this.isLoaded && ctx.drawImage(this.image, 0, 0, 32, 32, x, y, 32, 32);
}
}