forked from Code-Bullet/NEAT-Template-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.js
More file actions
26 lines (22 loc) · 710 Bytes
/
Sprite.js
File metadata and controls
26 lines (22 loc) · 710 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
function Sprite(sheet, w, h, frameCount) {
this.sheet = sheet;
this.w = w; //displayed width
this.h = h; //displayed height
this.frameCount = frameCount; //frames in sheet
this.frameWidth = this.sheet.width / this.frameCount;
this.frameHeight = this.sheet.height;
this.frame = 0;
this.draw = function() {
image(
this.sheet,
0, 0, this.w, this.h,
this.frameWidth * floor(this.frame), 0,
this.frameWidth, this.frameHeight
);
//animate
this.frame += 0.1;
if (this.frame >= this.frameCount) {
this.frame = 0;
}
}
}