-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGameObject.js
More file actions
56 lines (47 loc) · 1.64 KB
/
GameObject.js
File metadata and controls
56 lines (47 loc) · 1.64 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import Sprite from "./Sprite";
class GameObject {
constructor(config) {
this.x = config.x || 0;
this.y = config.y || 0;
this.direction = config.direction || "down"; // default to down (string)
this.sprite = new Sprite({
gameObject: this,
src: config.src || '/images/characters/people/hero.png', // If the object doesn't have a set image, provide a default
});
}
update() {
}
}
export default GameObject;
/* Original character/gameObject params:
// Character Creation
const x = 5; // x position for character/object
const y = 6; // y
const character = new Image();
character.onload = () => {
this.ctx.drawImage(character,
0, // Params for cropping the sprite pack -> left cut
0, // top cut
32, // Size of cut in pixels -> 32x32 (width)
32, // height of cut
x * 16 -8, // x pos of cut image
y * 16 -18, // * 16 -> compensating for the grid size, then move the character to the top left of the grid
32, // Size of character (in pixels)
32)
}
character.src = "/images/characters/character.png"
// Perspective/shadow for the character
const shadow = new Image();
shadow.onload = () => {
this.ctx.drawImage(shadow,
0,
0,
32,
32,
x * 16 -8,
y * 16 -18,
32,
32)
}
shadow.src = "images/characters/shadow.png"
*/