Class: Gamepad

Phaser.Input.Gamepad. Gamepad

A single Gamepad.

These are created, updated and managed by the Gamepad Plugin.


new Gamepad(manager, pad)

Parameters:
Name Type Description
manager Phaser.Input.Gamepad.GamepadPlugin

A reference to the Gamepad Plugin.

pad Phaser.Types.Input.Gamepad.Pad

The Gamepad object, as extracted from GamepadEvent.

Since: 3.0.0
Source: src/input/gamepad/Gamepad.js (Line 13)

Extends

Members


A :boolean

Is the Gamepad's bottom button in the right button cluster being pressed? If the Gamepad doesn't have this button it will always return false. On a Dual Shock controller it's the X button. On an XBox controller it's the A button.

Type:
  • boolean
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 609)

axes :Array.<Phaser.Input.Gamepad.Axis>

An array of Gamepad Axis objects, corresponding to the different axes available on the Gamepad, if any.

Type:
Since: 3.0.0
Source: src/input/gamepad/Gamepad.js (Line 105)

B :boolean

Is the Gamepad's right button in the right button cluster being pressed? If the Gamepad doesn't have this button it will always return false. On a Dual Shock controller it's the Circle button. On an XBox controller it's the B button.

Type:
  • boolean
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 666)

buttons :Array.<Phaser.Input.Gamepad.Button>

An array of Gamepad Button objects, corresponding to the different buttons available on the Gamepad.

Type:
Since: 3.0.0
Source: src/input/gamepad/Gamepad.js (Line 89)

connected :boolean

Is this Gamepad currently connected or not?

Type:
  • boolean
Since: 3.0.0
Default Value:
  • true
Source: src/input/gamepad/Gamepad.js (Line 504)

down :boolean

Is the Gamepad's Down button being pressed? If the Gamepad doesn't have this button it will always return false. This is the d-pad down button under standard Gamepad mapping.

Type:
  • boolean
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 591)

id :string

A string containing some information about the controller.

This is not strictly specified, but in Firefox it will contain three pieces of information separated by dashes (-): two 4-digit hexadecimal strings containing the USB vendor and product id of the controller, and the name of the controller as provided by the driver. In Chrome it will contain the name of the controller as provided by the driver, followed by vendor and product 4-digit hexadecimal strings.

Type:
  • string
Since: 3.0.0
Source: src/input/gamepad/Gamepad.js (Line 56)

index :number

An integer that is unique for each Gamepad currently connected to the system. This can be used to distinguish multiple controllers. Note that disconnecting a device and then connecting a new device may reuse the previous index.

Type:
  • number
Since: 3.0.0
Source: src/input/gamepad/Gamepad.js (Line 71)

L1 :number

Returns the value of the Gamepad's top left shoulder button. If the Gamepad doesn't have this button it will always return zero. The value is a float between 0 and 1, corresponding to how depressed the button is. On a Dual Shock controller it's the L1 button. On an XBox controller it's the LB button.

Type:
  • number
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 685)

L2 :number

Returns the value of the Gamepad's bottom left shoulder button. If the Gamepad doesn't have this button it will always return zero. The value is a float between 0 and 1, corresponding to how depressed the button is. On a Dual Shock controller it's the L2 button. On an XBox controller it's the LT button.

Type:
  • number
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 705)

left :boolean

Is the Gamepad's Left button being pressed? If the Gamepad doesn't have this button it will always return false. This is the d-pad left button under standard Gamepad mapping.

Type:
  • boolean
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 537)

leftStick :Phaser.Math.Vector2

A Vector2 containing the most recent values from the Gamepad's left axis stick. This is updated automatically as part of the Gamepad.update cycle. The H Axis is mapped to the Vector2.x property, and the V Axis to the Vector2.y property. The values are based on the Axis thresholds. If the Gamepad does not have a left axis stick, the values will always be zero.

Type:
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 291)

manager :Phaser.Input.Gamepad.GamepadPlugin

A reference to the Gamepad Plugin.

Type:
Since: 3.0.0
Source: src/input/gamepad/Gamepad.js (Line 38)

pad :any

A reference to the native Gamepad object that is connected to the browser.

Type:
  • any
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 47)

R1 :number

Returns the value of the Gamepad's top right shoulder button. If the Gamepad doesn't have this button it will always return zero. The value is a float between 0 and 1, corresponding to how depressed the button is. On a Dual Shock controller it's the R1 button. On an XBox controller it's the RB button.

Type:
  • number
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 725)

R2 :number

Returns the value of the Gamepad's bottom right shoulder button. If the Gamepad doesn't have this button it will always return zero. The value is a float between 0 and 1, corresponding to how depressed the button is. On a Dual Shock controller it's the R2 button. On an XBox controller it's the RT button.

Type:
  • number
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 745)

Is the Gamepad's Right button being pressed? If the Gamepad doesn't have this button it will always return false. This is the d-pad right button under standard Gamepad mapping.

Type:
  • boolean
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 555)

rightStick :Phaser.Math.Vector2

A Vector2 containing the most recent values from the Gamepad's right axis stick. This is updated automatically as part of the Gamepad.update cycle. The H Axis is mapped to the Vector2.x property, and the V Axis to the Vector2.y property. The values are based on the Axis thresholds. If the Gamepad does not have a right axis stick, the values will always be zero.

Type:
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 304)

timestamp :number

A timestamp containing the most recent time this Gamepad was updated.

Type:
  • number
Since: 3.0.0
Source: src/input/gamepad/Gamepad.js (Line 521)

up :boolean

Is the Gamepad's Up button being pressed? If the Gamepad doesn't have this button it will always return false. This is the d-pad up button under standard Gamepad mapping.

Type:
  • boolean
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 573)

vibration :GamepadHapticActuator

The Gamepad's Haptic Actuator (Vibration / Rumble support). This is highly experimental and only set if both present on the device, and exposed by both the hardware and browser.

Type:
  • GamepadHapticActuator
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 114)

X :boolean

Is the Gamepad's left button in the right button cluster being pressed? If the Gamepad doesn't have this button it will always return false. On a Dual Shock controller it's the Square button. On an XBox controller it's the X button.

Type:
  • boolean
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 647)

Y :boolean

Is the Gamepad's top button in the right button cluster being pressed? If the Gamepad doesn't have this button it will always return false. On a Dual Shock controller it's the Triangle button. On an XBox controller it's the Y button.

Type:
  • boolean
Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 628)

Methods


addListener(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 111)
Returns:

this.

Type
Phaser.Input.Gamepad.Gamepad

destroy()

Destroys this Gamepad instance, its buttons and axes, and releases external references it holds.

Since: 3.10.0
Overrides:
Source: src/input/gamepad/Gamepad.js (Line 475)

emit(event [, args])

Calls each of the listeners registered for a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

args * <optional>
<repeatable>

Additional arguments that will be passed to the event handler.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 86)
Returns:

true if the event had listeners, else false.

Type
boolean

eventNames()

Return an array listing the events for which the emitter has registered listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 55)
Returns:
Type
Array.<(string|symbol)>

getAxisTotal()

Gets the total number of axis this Gamepad claims to support.

Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 328)
Returns:

The total number of axes this Gamepad claims to support.

Type
number

getAxisValue(index)

Gets the value of an axis based on the given index. The index must be valid within the range of axes supported by this Gamepad. The return value will be a float between 0 and 1.

Parameters:
Name Type Description
index number

The index of the axes to get the value for.

Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 341)
Returns:

The value of the axis, between 0 and 1.

Type
number

getButtonTotal()

Gets the total number of buttons this Gamepad claims to have.

Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 375)
Returns:

The total number of buttons this Gamepad claims to have.

Type
number

getButtonValue(index)

Gets the value of a button based on the given index. The index must be valid within the range of buttons supported by this Gamepad.

The return value will be either 0 or 1 for an analogue button, or a float between 0 and 1 for a pressure-sensitive digital button, such as the shoulder buttons on a Dual Shock.

Parameters:
Name Type Description
index number

The index of the button to get the value for.

Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 388)
Returns:

The value of the button, between 0 and 1.

Type
number

isButtonDown(index)

Returns if the button is pressed down or not. The index must be valid within the range of buttons supported by this Gamepad.

Parameters:
Name Type Description
index number

The index of the button to get the value for.

Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 407)
Returns:

true if the button is considered as being pressed down, otherwise false.

Type
boolean

listenerCount(event)

Return the number of listeners listening to a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 75)
Returns:

The number of listeners.

Type
number

listeners(event)

Return the listeners registered for a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 64)
Returns:

The registered listeners.

Type
Array.<function()>

off(event [, fn] [, context] [, once])

Remove the listeners of a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 151)
Returns:

this.

Type
Phaser.Input.Gamepad.Gamepad

on(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 98)
Returns:

this.

Type
Phaser.Input.Gamepad.Gamepad

once(event, fn [, context])

Add a one-time listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 124)
Returns:

this.

Type
Phaser.Input.Gamepad.Gamepad

removeAllListeners( [event])

Remove all listeners, or those of the specified event.

Parameters:
Name Type Argument Description
event string | symbol <optional>

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 165)
Returns:

this.

Type
Phaser.Input.Gamepad.Gamepad

removeListener(event [, fn] [, context] [, once])

Remove the listeners of a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 137)
Returns:

this.

Type
Phaser.Input.Gamepad.Gamepad

setAxisThreshold(value)

Sets the threshold value of all axis on this Gamepad. The value is a float between 0 and 1 and is the amount below which the axis is considered as not having been moved.

Parameters:
Name Type Description
value number

A value between 0 and 1.

Since: 3.10.0
Source: src/input/gamepad/Gamepad.js (Line 358)

shutdown()

Removes all listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 31)