Spaces:
Running
Running
File size: 659 Bytes
020d2dc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // Clip playback. Rate and frame count come from the manifest; this file has no
// opinion about either.
export function createPlayer(clip) {
return {
clip,
time: 0,
reset() { this.time = 0; },
advance(dt) { this.time += dt; },
get index() {
const raw = Math.floor(this.time * this.clip.fps);
if (!this.clip.loop) return Math.min(Math.max(raw, 0), this.clip.count - 1);
return ((raw % this.clip.count) + this.clip.count) % this.clip.count;
},
get finished() {
return !this.clip.loop && this.time * this.clip.fps >= this.clip.count - 1;
},
frame() { return this.clip.frames[this.index]; },
};
}
|