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
27 lines (23 loc) · 741 Bytes
/
Copy pathSprite.js
File metadata and controls
27 lines (23 loc) · 741 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
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(x, y) {
imageMode(CENTER);
image(
this.sheet,
x, y, 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;
}
}
}