@g20/player
Version:
Window Animation Frame Player
45 lines (42 loc) • 1.11 kB
JavaScript
/**
* @g20/player 1.0.0-alpha.46
* (c) David Geo Holmes david.geo.holmes@gmail.com
* Released under the MIT License.
*/
import { effect } from '@g20/reactive';
class Player {
#board;
#frameCount;
/**
* The handle of the last frame requested.
*/
#handle = null;
constructor(board, callback) {
this.#board = board;
this.#frameCount = effect(() => {
callback(board.frameCount);
});
}
dispose() {
if (this.#frameCount) {
this.#frameCount.dispose();
}
}
play() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const animate = (timestamp) => {
this.#handle = null;
this.#board.update();
this.#handle = window.requestAnimationFrame(animate);
};
this.#handle = window.requestAnimationFrame(animate);
}
pause() {
if (typeof this.#handle === "number") {
window.cancelAnimationFrame(this.#handle);
this.#handle = null;
}
}
}
export { Player };
//# sourceMappingURL=index.js.map