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