forked from danielgtaylor/html5-space-fighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate.js
37 lines (27 loc) · 919 Bytes
/
animate.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
var gamejs = require('gamejs');
var AnimatedSprite = function () {
AnimatedSprite.superConstructor.apply(this, arguments);
this.rect = null;
this.frames = [];
this.currentFrame = 0;
this.animationSpeed = 250;
this.frameTimer = 0;
this.updateAnimation = function (msDuration) {
this.frameTimer -= msDuration;
while (this.frameTimer <= 0) {
this.currentFrame += 1;
if (this.currentFrame >= this.frames.length) {
this.currentFrame = 0;
}
this.frameTimer += this.animationSpeed;
}
};
this.update = function (msDuration) {
this.updateAnimation(msDuration);
};
this.draw = function (surface) {
surface.blit(this.frames[this.currentFrame], this.rect);
};
};
gamejs.utils.objects.extend(AnimatedSprite, gamejs.sprite.Sprite);
exports.AnimatedSprite = AnimatedSprite;