Navigation
These archived docs are for Phaser 2.3.0 Phaser 3 docs can be found on newdocs.phaser.io.
Phaser CE docs can be found on the Phaser CE Documentation site.

Constructor

Phaser. GamepadButton

new GamepadButton(pad, buttonCode)

If you need more fine-grained control over the handling of specific buttons you can create and use Phaser.GamepadButton objects.

Parameters
Name Type Description
pad Phaser.SinglePad

A reference to the gamepad that owns this button.

buttonCode number

The button code this GamepadButton is responsible for.

Source code: input/GamepadButton.js (Line 16)

Public Properties

buttonCode : number

The buttoncode of this button.

Source code: input/GamepadButton.js (Line 75)

duration : number

If the button is down this value holds the duration of that button press and is constantly updated. If the button is up it holds the duration of the previous down session. The number of milliseconds this button has been held down for.

Default Value
  • 0
Source code: input/GamepadButton.js (Line 52)

game : Phaser.Game

A reference to the currently running game.

Source code: input/GamepadButton.js (Line 26)

isDown : boolean

The "down" state of the button.

Default Value
  • false
Source code: input/GamepadButton.js (Line 32)

isUp : boolean

The "up" state of the button.

Default Value
  • true
Source code: input/GamepadButton.js (Line 38)

onDown : Phaser.Signal

This Signal is dispatched every time this GamepadButton is pressed down. It is only dispatched once (until the button is released again).

Source code: input/GamepadButton.js (Line 80)

onFloat : Phaser.Signal

This Signal is dispatched every time this GamepadButton changes floating value (between (but not exactly) 0 and 1)

Source code: input/GamepadButton.js (Line 90)

onUp : Phaser.Signal

This Signal is dispatched every time this GamepadButton is pressed down. It is only dispatched once (until the button is released again).

Source code: input/GamepadButton.js (Line 85)

pad : Phaser.SinglePad

A reference to the gamepad that owns this button.

Source code: input/GamepadButton.js (Line 21)

repeats : number

If a button is held down this holds down the number of times the button has 'repeated'.

Default Value
  • 0
Source code: input/GamepadButton.js (Line 64)

timeDown : number

The timestamp when the button was last pressed down.

Default Value
  • 0
Source code: input/GamepadButton.js (Line 44)

timeUp : number

The timestamp when the button was last released.

Default Value
  • 0
Source code: input/GamepadButton.js (Line 58)

value : number

Button value. Mainly useful for checking analog buttons (like shoulder triggers)

Default Value
  • 0
Source code: input/GamepadButton.js (Line 70)

Public Methods

destroy()

Destroys this GamepadButton, this disposes of the onDown, onUp and onFloat signals and clears the pad and game references.

Source code: input/GamepadButton.js (Line 194)

justPressed(duration) → {boolean}

Returns the "just pressed" state of this button. Just pressed is considered true if the button was pressed down within the duration given (default 250ms).

Parameters
Name Type Argument Default Description
duration number <optional>
250

The duration below which the button is considered as being just pressed.

Returns
boolean -

True if the button is just pressed otherwise false.

Source code: input/GamepadButton.js (Line 149)

justPressed(duration) → {boolean}

Returns the "just released" state of this button. Just released is considered as being true if the button was released within the duration given (default 250ms).

Parameters
Name Type Argument Default Description
duration number <optional>
250

The duration below which the button is considered as being just released.

Returns
boolean -

True if the button is just pressed otherwise false.

Source code: input/GamepadButton.js (Line 164)

<internal> processButtonDown(value)

Called automatically by Phaser.SinglePad.

Parameters
Name Type Description
value number

Button value

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/GamepadButton.js (Line 96)

<internal> processButtonFloat(value)

Called automatically by Phaser.SinglePad.

Parameters
Name Type Description
value number

Button value

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/GamepadButton.js (Line 134)

<internal> processButtonUp(value)

Called automatically by Phaser.SinglePad.

Parameters
Name Type Description
value number

Button value

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: input/GamepadButton.js (Line 116)

reset()

Resets this GamepadButton, changing it to an isUp state and resetting the duration and repeats counters.

Source code: input/GamepadButton.js (Line 179)