Wrapper for the Gamepad API that smooths out browser inconsistancies. Exposes changes to gamepads, buttons and axes as events.

Hierarchy

  • GamepadApiWrapper

Constructors

Properties

axisDeadZone: number
buttonConfigs: wrapperButtonConfig[]
currentStateOfGamepads: Gamepad[]
gamepadAxisChangeListeners: AxisChangeCallback[]
gamepadButtonChangeListeners: ButtonChangeCallback[]
gamepadConnectListeners: GamepadEventCallback[]
gamepadDisconnectListeners: GamepadEventCallback[]
updateDelay: number

Methods

  • gamepadApiSupported: returns true if the gamepad api is supported by the browser context

    Returns boolean

  • Returns the result of navigator.getGamepads() from the last update

    Returns

    An array of gamepad objects, or an empty array if the gamepad api is not supported

    Parameters

    • forceUpdate: boolean = false

      If true, navigator.getGamepads() will be called inmediately before returning, if gamepad changes happened since the last update, this will cause those change events to fire.

    Returns Gamepad[]

  • offGamepadAxisChange: remove an existing event listener for when a gamepad axis changes

    Parameters

    • Callback: AxisChangeCallback

      The calback function to remove (must be the same function passed to onGamepadAxisChange())

    Returns void

  • offGamepadButtonChange: remove an existing event listener for when a gamepad button changes

    Parameters

    • Callback: ButtonChangeCallback

      The calback function to remove (must be the same function passed to onGamepadButtonChange())

    Returns void

  • remove an existing event listener for when a gamepad (either real or emulated) is disconnected

    Parameters

    • Callback: GamepadEventCallback

      The calback function to remove (must be the same function passed to onGamepadDisconnect())

    Returns void

  • onGamepadButtonChange add an event listener for each time a gamepad button changes. The callback function will be called with the gamepad index, the gamepad object, and a array of the changed buttons containing details about how the button transitioned or false if the button state didn't change this frame. Callback is called separately for each gamepad where buttons have changed.

    Parameters

    Returns ButtonChangeCallback

Generated using TypeDoc