Class to handle displaying the state of a gamepad on the screen. This class will not draw anything to the screen. Instead it will update the classes / transforms of the elements you provide to represent the buttons and axes of the gamepad. See the examples for more information.

Constructors

Properties

apiWrapper: GamepadApiWrapper
displayButtonChanges: ButtonChangeCallback = ...

This function is registered as the callback for () it calls the DisplayGamepadConfig.buttonDisplayFunction (if specified) or the GamepadDisplay.DefaultButtonDisplayFunction otherwise for every button that has changed since the last update

The index of the gamepad that has changed

The new state of the gamepad as reported by the browser / GamepadApiWrapper.onGamepadButtonChange

An array of buttonChangeDetails or false, where each false in the array indicates that the corresponding button index has not changed since the last update.

displayJoystickChanges: AxisChangeCallback = ...

This function is registered as the callback for () it calls the DisplayGamepadConfig.joystickDisplayFunction (if specified) or the GamepadDisplay.DefaultJoystickDisplayFunction otherwise for each configured joystick with axies that have changed

The index of the gamepad that has changed

The new state of the gamepad as reported by the browser

An array of booleans, where each true indicates that the corresponding axis has changed since the last update

Methods

  • Cleanup function to remove all event listeners created by the GamepadDisplay Call this function before removing the gamepad display from the DOM or deleting the GamepadDisplay instance to prevent memory leaks

    Returns void

  • Function called by default when any gamepad buttons change (called separately for each button (as configured in this GamepadDisplay)) If you specify your own DisplayGamepadConfig.buttonDisplayFunction in the config, this function won't get called. Instead, you can call this function with the same parameters as passed to the DisplayGamepadConfig.buttonDisplayFunction if you want to keep the default behaviour (and then you can add your own custom behaviour on top)

    Parameters

    • buttonConfig: GamepadDisplayButton

      The config for the button that has changed as configured in DisplayGamepadConfig.buttons

    • value: number

      The new value of the button

    • touched: boolean

      Whether the button is currently being touched (unused, but included for consistency with the ButtonDisplayFunction signature)

    • pressed: boolean

      Whether the button is currently being pressed (unused, but included for consistency with the ButtonDisplayFunction signature)

    • changes: buttonChangeDetails

      The changes that have occurred since the last update

    • btnIndex: number

      The index of the button that has changed (unused, but included for consistency with the ButtonDisplayFunction signature)

    Returns void