Button
Represents a single button on a Gamepad controller. Each Button has a value between 0 and 1 (supporting analog pressure for triggers) and a pressed boolean state. When the value exceeds the configurable threshold, the button emits BUTTON_DOWN and GAMEPAD_BUTTON_DOWN events. Button objects are created automatically by the Gamepad as they are needed.
Constructor
new Button(pad, index, [isPressed])
Parameters
| name | type | optional | default | description |
|---|---|---|---|---|
| pad | Phaser.Input.Gamepad.Gamepad | No | A reference to the Gamepad that this Button belongs to. | |
| index | number | No | The index of this Button. | |
| isPressed | boolean | Yes | false | Whether or not the button is already being pressed at creation time. This prevents the Button from emitting spurious 'down' events at first update. |
Scope: static
Source: src/input/gamepad/Button.js#L10
Since: 3.0.0
Public Members
events
events: Phaser.Events.EventEmitter
Description:
An event emitter to use to emit the button events.
Source: src/input/gamepad/Button.js#L43
Since: 3.0.0
index
index: number
Description:
The index of this Button.
Source: src/input/gamepad/Button.js#L52
Since: 3.0.0
pad
pad: Phaser.Input.Gamepad.Gamepad
Description:
A reference to the Gamepad that this Button belongs to.
Source: src/input/gamepad/Button.js#L34
Since: 3.0.0
pressed
pressed: boolean
Description:
Is the Button being pressed down or not?
Source: src/input/gamepad/Button.js#L84
Since: 3.0.0
threshold
threshold: number
Description:
The minimum value the button must reach before it is considered as being pressed. The value is between 0 and 1. The default of 1 requires the button to be fully pressed. For analog buttons such as triggers, you can lower this threshold to detect partial presses.
Source: src/input/gamepad/Button.js#L72
Since: 3.0.0
value
value: number
Description:
The current value of the button, between 0 (fully released) and 1 (fully pressed). For analog buttons like triggers, this reflects the pressure applied.
Source: src/input/gamepad/Button.js#L61
Since: 3.0.0
Public Methods
destroy
<instance> destroy()
Description:
Destroys this Button instance and releases external references it holds.
Source: src/input/gamepad/Button.js#L133
Since: 3.10.0