A lightweight JavaScript game engine
git clone git://soophie.de/game-engine
blob: 1bbd505577e58c48cc5b9da07d073526bfa208f7 (445 bytes)[doc][blame][raw]
1
import Timer from './timer.js';3
export default class Animation {4
constructor(size, step) {5
this.size = size;6
this.timer = new Timer(step);7
this.frame = 0;8
this.offset = 0;9
}10
count() {11
if(this.timer.count()) {12
if(this.frame === this.size - 1) {13
this.frame = 0;14
}15
else {16
this.frame++;17
}18
}19
}20
reset() {21
this.timer.reset();22
this.frame = 0;23
}24
get(sprites) {25
return sprites[this.offset + this.frame];26
}27
}