dot big bang

Developer API
Menu

Class Gamepad

All
  • Public
  • Public/Protected
  • All

Hierarchy

  • Gamepad

Index

Constructors

constructor

Properties

Readonly axes

axes: number[]

The array of values for all axes of the gamepad. All axis values are linearly normalized to the range [-1.0 .. 1.0]. If the gamepad is perpendicular to the ground with the directional stick pointing up, -1.0 normally corresponds to "forward" or "left", and 1.0 normally corresponds to "backward" or "right". Axes that are drawn from a 2D input device normally appear next to each other in the axes array, X then Y. Axes should appear in decreasing order of importance in the array, such that element 0 and 1 typically represent the X and Y axis of a directional stick.

Readonly buttons

buttons: GamepadButton[]

The array of button states for all buttons of the gamepad. The buttons should appear in decreasing importance such that the primary button, secondary button, tertiary button, and so on appear as elements 0, 1, 2, ... in the buttons array.

Readonly connected

connected: boolean

Indicates whether the physical gamepad represented by this object is still connected to the local machine. When a gamepad becomes unavailable, whether by being physically disconnected, powered off or otherwise unusable, this property is set to false.

Readonly id

id: string

The identification string for the gamepad. This string identifies the brand or style of connected gamepad device. Typically, this will include the USB vendor and a product ID.

Readonly index

index: number

The index of the gamepad in array in the Input object (see game.input.gamepads).

Readonly mapping

mapping: string

The mapping in use for this gamepad. When the browser has knowledge of the physical layout of the device, it presents the buttons and axes in a well-defined configuration, which is what the mapping property represents. For now, the only supported mapping is called 'standard' and refers to typical console gamepads. A diagram illustrating it can be found here https://w3c.github.io/gamepad/#dfn-standard-gamepad-layout. The 'standard' mapping should apply in most browsers/OS for common gamepads such as the Xbox 360, Xbox One, Playstation 4 DualShock 4, etc... When the browser doesn't have specific knowledge of the gamepad, the mapping property is the empty string, and the order and index of each button and axis can potentially be quite exotic.

Methods

getHeldTime

  • getHeldTime(buttonIndex: number): number
  • Returns how long the button has been held (0 if it's not held) in seconds.

    Parameters

    • buttonIndex: number

    Returns number

isButtonJustPressed

  • isButtonJustPressed(buttonIndex: number): boolean
  • Indicates whether the given button was just pressed this frame.

    Parameters

    • buttonIndex: number

    Returns boolean

isButtonJustReleased

  • isButtonJustReleased(buttonIndex: number): boolean
  • Indicates whether the given button was just released this frame.

    Parameters

    • buttonIndex: number

    Returns boolean