@g20/player
Version:
Window Animation Frame Player
47 lines (43 loc) • 1.15 kB
JavaScript
/**
* @g20/player 1.0.0-alpha.46
* (c) David Geo Holmes david.geo.holmes@gmail.com
* Released under the MIT License.
*/
;
var reactive = require('@g20/reactive');
class Player {
#board;
#frameCount;
/**
* The handle of the last frame requested.
*/
#handle = null;
constructor(board, callback) {
this.#board = board;
this.#frameCount = reactive.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;
}
}
}
exports.Player = Player;
//# sourceMappingURL=index.js.map