Phaser API Documentation

  Version: 
Filter

A single Gamepad.

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

Constructor:

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

Extends


Members

A: boolean
Focus
Focus

Description:

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
Focus
Focus
B: boolean
Focus
Focus

Description:

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
Focus
Focus
L1: number
Focus
Focus

Description:

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
Focus
Focus
L2: number
Focus
Focus

Description:

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
Focus
Focus
R1: number
Focus
Focus

Description:

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
Focus
Focus
R2: number
Focus
Focus

Description:

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
Focus
Focus
X: boolean
Focus
Focus

Description:

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
Focus
Focus
Y: boolean
Focus
Focus

Description:

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
Focus
Focus
<private> _FBLeftBottom: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Bottom Left Front Button (L2 Shoulder Button)

Type:
Since: 3.10.0
Focus
Focus
<private> _FBLeftTop: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Top Left Front Button (L1 Shoulder Button)

Type:
Since: 3.10.0
Focus
Focus
<private> _FBRightBottom: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Bottom Right Front Button (R2 Shoulder Button)

Type:
Since: 3.10.0
Focus
Focus
<private> _FBRightTop: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Top Right Front Button (R1 Shoulder Button)

Type:
Since: 3.10.0
Focus
Focus
<private> _HAxisLeft: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Horizontal Axis for the Left Stick.

Type:
Since: 3.10.0
Focus
Focus
<private> _HAxisRight: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Horizontal Axis for the Right Stick.

Type:
Since: 3.10.0
Focus
Focus
<private> _LCBottom: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Bottom Button in the Left Cluster.

Type:
Since: 3.10.0
Focus
Focus
<private> _LCLeft: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Left Button in the Left Cluster.

Type:
Since: 3.10.0
Focus
Focus
<private> _LCRight: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Right Button in the Left Cluster.

Type:
Since: 3.10.0
Focus
Focus
<private> _LCTop: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Top Button in the Left Cluster.

Type:
Since: 3.10.0
Focus
Focus
<private> _RCBottom: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Bottom Button in the Right Cluster.

Type:
Since: 3.10.0
Focus
Focus
<private> _RCLeft: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Left Button in the Right Cluster.

Type:
Since: 3.10.0
Focus
Focus
<private> _RCRight: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Right Button in the Right Cluster.

Type:
Since: 3.10.0
Focus
Focus
<private> _RCTop: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Top Button in the Right Cluster.

Type:
Since: 3.10.0
Focus
Focus
<private> _VAxisLeft: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Vertical Axis for the Left Stick.

Type:
Since: 3.10.0
Focus
Focus
<private> _VAxisRight: Phaser.Input.Gamepad.Button
Focus
Focus

Description:

A reference to the Vertical Axis for the Right Stick.

Type:
Since: 3.10.0
Focus
Focus
<private> _created: number
Focus
Focus

Description:

When was this Gamepad created? Used to avoid duplicate event spamming in the update loop.

Type:
number
Since: 3.50.0
Focus
Focus

Description:

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

Type:
Since: 3.0.0
Focus
Focus
buttons: Array.<Phaser.Input.Gamepad.Button>
Focus
Focus

Description:

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

Type:
Since: 3.0.0
Focus
Focus
connected: boolean
Focus
Focus

Description:

Is this Gamepad currently connected or not?

Type:
boolean
Default: true
Since: 3.0.0
Focus
Focus
down: boolean
Focus
Focus

Description:

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
Focus
Focus
id: string
Focus
Focus

Description:

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
Focus
Focus
index: number
Focus
Focus

Description:

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
Focus
Focus
left: boolean
Focus
Focus

Description:

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
Focus
Focus
leftStick: Phaser.Math.Vector2
Focus
Focus

Description:

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
Focus
Focus

Description:

A reference to the Gamepad Plugin.

Type:
Since: 3.0.0
Focus
Focus
pad: any
Focus
Focus

Description:

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

Type:
any
Since: 3.10.0
Focus
Focus
rightStick: Phaser.Math.Vector2
Focus
Focus

Description:

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
Focus
Focus
timestamp: number
Focus
Focus

Description:

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

Type:
number
Since: 3.0.0
Focus
Focus
up: boolean
Focus
Focus

Description:

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
Focus
Focus
vibration: GamepadHapticActuator
Focus
Focus

Description:

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
Focus
Focus

Methods

addListener(event, fn, [context])
Focus
Focus

Description:

Add a listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#addListener
Since: 3.0.0
Focus
Focus
destroy()
Focus
Focus

Description:

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

Overrides: Phaser.Events.EventEmitter#destroy
Since: 3.10.0
Focus
Focus
emit(event, [args])
Focus
Focus

Description:

Calls each of the listeners registered for a given event.

Parameters:

name type arguments description
event string | symbol

The event name.

args * <optional>

Additional arguments that will be passed to the event handler.

Returns:
Description:

true if the event had listeners, else false.

Type:
  • boolean
Inherited from: Phaser.Events.EventEmitter#emit
Since: 3.0.0
Focus
Focus
eventNames()
Focus
Focus

Description:

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

Type:
  • Array.<(string
  • symbol)>
Inherited from: Phaser.Events.EventEmitter#eventNames
Since: 3.0.0
Focus
Focus
getAxisTotal()
Focus
Focus

Description:

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

Returns:
Description:

The total number of axes this Gamepad claims to support.

Type:
  • number
Since: 3.10.0
Focus
Focus
getAxisValue(index)
Focus
Focus

Description:

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.

Returns:
Description:

The value of the axis, between 0 and 1.

Type:
  • number
Since: 3.10.0
Focus
Focus
getButtonTotal()
Focus
Focus

Description:

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

Returns:
Description:

The total number of buttons this Gamepad claims to have.

Type:
  • number
Since: 3.10.0
Focus
Focus
getButtonValue(index)
Focus
Focus

Description:

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.

Returns:
Description:

The value of the button, between 0 and 1.

Type:
  • number
Since: 3.10.0
Focus
Focus
isButtonDown(index)
Focus
Focus

Description:

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.

Returns:
Description:

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

Type:
  • boolean
Since: 3.10.0
Focus
Focus
listenerCount(event)
Focus
Focus

Description:

Return the number of listeners listening to a given event.

Parameters:

name type description
event string | symbol

The event name.

Returns:
Description:

The number of listeners.

Type:
  • number
Inherited from: Phaser.Events.EventEmitter#listenerCount
Since: 3.0.0
Focus
Focus
listeners(event)
Focus
Focus

Description:

Return the listeners registered for a given event.

Parameters:

name type description
event string | symbol

The event name.

Returns:
Description:

The registered listeners.

Type:
  • Array.<function()>
Inherited from: Phaser.Events.EventEmitter#listeners
Since: 3.0.0
Focus
Focus
off(event, [fn], [context], [once])
Focus
Focus

Description:

Remove the listeners of a given event.

Parameters:

name type arguments 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.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#off
Since: 3.0.0
Focus
Focus
on(event, fn, [context])
Focus
Focus

Description:

Add a listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#on
Since: 3.0.0
Focus
Focus
once(event, fn, [context])
Focus
Focus

Description:

Add a one-time listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#once
Since: 3.0.0
Focus
Focus
removeAllListeners([event])
Focus
Focus

Description:

Remove all listeners, or those of the specified event.

Parameters:

name type arguments description
event string | symbol <optional>

The event name.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#removeAllListeners
Since: 3.0.0
Focus
Focus
removeListener(event, [fn], [context], [once])
Focus
Focus

Description:

Remove the listeners of a given event.

Parameters:

name type arguments 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.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#removeListener
Since: 3.0.0
Focus
Focus
setAxisThreshold(value)
Focus
Focus

Description:

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
Focus
Focus
shutdown()
Focus
Focus

Description:

Removes all listeners.

Inherited from: Phaser.Events.EventEmitter#shutdown
Since: 3.0.0
Focus
Focus
<private> update()
Focus
Focus

Description:

Internal update handler for this Gamepad. Called automatically by the Gamepad Manager as part of its update.

Since: 3.0.0
Focus
Focus