Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Tool for gamepad support in HTML5 games

A topic by 3p0ch created Jul 10, 2022 Views: 253 Replies: 1
Viewing posts 1 to 2

Gamepad support in HTML5 games is currently pretty bad. Even if a framework or game engine says it supports them, in practice I've found it to be very unreliable especially when using different gamepads on different systems, primarily because the underlying JavaScript Gamepad API doesn't map buttons and sticks consistently. If there are reliable implementations out there, I haven't found them.

So I wrote a tool in JavaScript that you can launch from within your game that asks the player to press all the buttons and move all the sticks on their gamepad while it listens, stores that data in their browser's LocalStorage where games can read it, and then sends them back to your game. A nice aspect is that if the player configures their gamepad from ANY game on the site, EVERY game on the site can read the data and use it for gamepad support without them needing to run the tool again.

The Gamepad mapper page is linked here, and you can see how I used it in practice in my game Quad. The Gamepad mapper's page has links to demos showing the gamepad mapper being used in Unity, Godot, HaxeFlixel, and pure JavaScript including instructions and source code for those implementations in the author comments.

The Tabageos ControllerPad Class does a similar thing. It will tell the user to press the input buttons and defines each button that way from user input.
For most pads the directional buttons don't need to be user defined since they all mostly operate by axis.