-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimatedSprite.js
45 lines (39 loc) · 938 Bytes
/
AnimatedSprite.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
38
39
40
41
42
43
44
45
import Sprite from "../Sprite/Sprite";
/**
* Sprites collection to animate.
*/
export default class AnimatedSprite extends Sprite {
/**
* @return {Number}
*/
getLoopDuration() {
return this._loopDuration;
}
/**
* @return {Number}
*/
getCurrentFrame() {
return this._currentFrame;
}
/**
* @param {[ImageData]} map
* @param {Number} loopDuration
* @param {Number} startingFrame
*/
constructor(map, loopDuration, startingFrame = 0) {
super(map[0]);
this._map = map;
this._loopDuration = loopDuration;
this._currentFrame = startingFrame;
}
/**
* Loop over Sprite collection
*/
step() {
this._currentFrame += 1;
if(this._currentFrame > this._map.length - 1) {
this._currentFrame = 0;
}
this._imgData = this._map[this._currentFrame];
}
}