gamepad.js
Version:
A simple HTML5 Gamepad handler that provides keyboard-like events for Gamepad axes and button
35 lines (27 loc) • 648 B
JavaScript
export default class Loop {
constructor(callback) {
this.callback = callback;
this.frame = null;
this.update = this.update.bind(this);
}
setCallback(callback) {
this.callback = callback;
}
start() {
if (this.frame) {
return;
}
this.frame = window.requestAnimationFrame(this.update);
}
stop() {
if (!this.frame) {
return;
}
window.cancelAnimationFrame(this.frame);
this.frame = null;
}
update() {
this.frame = window.requestAnimationFrame(this.update);
this.callback();
}
}