Creates the instance and assigns event handlers to gamepad events
Object containing the callback for when a controller is connected
Controllers connected before an event listener caught them.
Controllers connected before an event listener caught them.
Object containing the callback for when a controller is disconnected
The version of the module.
The logger module this module uses to log errors / logs.
Static getGets the main controller
The main controller or null if none set
Gets a specific controller by index
The index of the controller
The controller or null if not found
Gets all connected controllers as an array
Array of all connected controllers
Gets all controllers with metadata
Array of controller objects with metadata
Attaches a callback to the specified event.
The event to attach the callback to
The function to be called when the event is triggered
The GamepadManagerSingleton instance
Starts the library-owned requestAnimationFrame polling loop.
Use this for the library-managed polling mode. It is idempotent, so calling
it while polling is already active does not create another loop. Do not
call this if the host is polling with pollGamepadStateOnce().
Stops the library-owned requestAnimationFrame polling loop.
This does not disconnect controllers or clear their cached state. It only
transfers polling responsibility to the host. Pair it with one
pollGamepadStateOnce() call per host frame when the game owns its loop.
Polls controller state exactly once.
Hosts with an existing game loop should call stopPolling() once and then
call this method once per frame. It reads navigator.getGamepads(), updates
every connected controller, and may emit button/analog events. Avoid doing
expensive work or allocating heavily inside those callbacks because this
method normally runs at frame rate.
A Gamepad API manager for games and interactive applications.
Polling ownership
The manager starts an internal
requestAnimationFramepolling loop when it is constructed. This is the easiest option for menus, tools, and small applications: connect/disconnect events are handled automatically and controller state changes are delivered without any setup beyond registering listeners.Games that already own a single authoritative frame loop should use the host-controlled option instead:
Do not use both polling modes. Running the library loop and calling
pollGamepadStateOnce()from another loop reads and processes the same controller state twice per frame. That creates redundant work, can duplicate event callbacks, and can make input race the host's simulation order.The tradeoff is simple:
The library normalizes device state and emits controller events. It does not decide whether mouse, touch, or another controller owns a game's input; that arbitration belongs in the host game's input manager.
GamepadManagerSingleton
License
GamepadManager does not have a license at this time. For licensing contact the author
Author
https://github.com/doubleactii
Todo
Currently bluetooth gamepads when disconnecting (PS4 only) do no fire a disconnected event. Manually calling
this.gamepad.vibrationActuator.reset()can force it to call a disconnect event, but this is a messy way of checking each tick to see if the gamepad is still connected. It also will cancel ongoing vibrations. Find a fix. (This is a GamepadAPI issue/OS issue/not code wise issue)