-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawable.js
37 lines (31 loc) · 953 Bytes
/
drawable.js
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
function Drawable() {
// Position
this.x;
this.y;
// Display
this.nbSprites;
this.sprites = [];
this.spriteOffset = -1;
this.scl;
// Collision
this.size
// Movement
this.speed = 0;
this.getSize = function() {
return this.size;
}
this.setSprites = function(entityName, nbSprites) {
this.sprites = getAssetManager().getSprites(entityName, nbSprites);
this.size = min(this.sprites[0].width, this.sprites[0].height) / this.scl;
if (this.spriteOffset == -1) {
this.spriteOffset = Math.ceil(random(0, this.nbSprites));
}
}
this.draw = function() {
this.setSprites(this.getSpriteName(), this.nbSprites);
if (this.sprites.length == 0) { return; }
img = this.sprites[frameCount % this.nbSprites];
imageMode(CENTER);
image(img, this.x, this.y, img.width / this.scl, img.height / this.scl);
}
}