NOOT: oud demo project, niet meer relevant omdat excalibur gamepad support heeft.
The arcade class will detect if you use a gamepad ๐ฎ or the arcade cabinet joystick ๐น
Run next line in your project terminal:
npm install git@github.com:HR-CMGT/arcade-game.git
import { Arcade } from "arcade-game"
export class Game {
#arcade;
#joystickListener;
constructor() {
//TODO: add reference to startGame()
}
startGame() {
this.#arcade = new Arcade(this, false, true);
this.#joystickListener = (e) => this.#joyStickFound(e)
document.addEventListener("joystickcreated", this.#joystickListener)
}
#joyStickFound(e) {
let joystick = this.#arcade.Joysticks[e.detail]
// debug, this shows you the names of the buttons when they are pressed
for (const buttonEvent of joystick.ButtonEvents) {
document.addEventListener(buttonEvent, () => console.log(buttonEvent))
}
this.update();
}
// excalibur update function
onPreUpdate() {
for (let joystick of this.#arcade.Joysticks) {
joystick.update()
}
}
// voorbeeld zonder excalibur
/*
update() {
for (let joystick of this.#arcade.Joysticks) {
joystick.update()
}
requestAnimationFrame(() => this.update());
}
*/
disconnect() {
document.removeEventListener("joystickcreated", this.#joystickListener)
}
}
new Game()