binji / binjgb

Gameboy emulator implemented in C, that also runs in the browser
https://binji.github.io/binjgb/
MIT License
534 stars 61 forks source link

Add html5 gamepad support to demo.js #37

Closed bbbbbr closed 3 years ago

bbbbbr commented 3 years ago

Adds HTML5 gamepad support to demo.js.

When w3c "standard" gamepad mapping is available the buttons will map to the expected locations of A/B/Start/Select, otherwise the first 4 (non-axis) buttons found map to A/B/Select/Start. Chrome seems to do a better job at detecting gamepad mapping than Firefox.

Gamepad support co-exists and does not interfere with keyboard controls. Polling only starts if a button is pressed on gamepad the window has foxus. Polling will stop if the gamepad disconnects or the emulator has destroy called, and can resume again if a new rom is loaded.

The gamepad code is almost all contained in a Gamepad class.

Testable here: https://bbbbbr.github.io/binjgb/demo/demo.html