Class: SinglePad

Phaser. SinglePad

new SinglePad(game, padParent)

A single Phaser Gamepad

Parameters:
Name Type Description
game Phaser.Game

Current game instance.

padParent object

The parent Phaser.Gamepad object (all gamepads reside under this)

Source:
src/input/SinglePad.js line 16

Members

callbackContext : object

The context under which the callbacks are run.

Type:
  • object
Source:
src/input/SinglePad.js line 38

<readonly> connected : boolean

Whether or not this particular gamepad is connected or not.

Type:
  • boolean
Source:
src/input/SinglePad.js line 33

deadZone : number

Dead zone for axis feedback - within this value you won't trigger updates.

Type:
  • number
Source:
src/input/SinglePad.js line 73

game : Phaser.Game

Local reference to game.

Type:
Source:
src/input/SinglePad.js line 21

<readonly> index : number

The gamepad index as per browsers data

Type:
  • number
Source:
src/input/SinglePad.js line 27

onAxisCallback : function

This callback is invoked every time an axis is changed.

Type:
  • function
Source:
src/input/SinglePad.js line 63

onConnectCallback : function

This callback is invoked every time this gamepad is connected

Type:
  • function
Source:
src/input/SinglePad.js line 43

onDisconnectCallback : function

This callback is invoked every time this gamepad is disconnected

Type:
  • function
Source:
src/input/SinglePad.js line 48

onDownCallback : function

This callback is invoked every time a button is pressed down.

Type:
  • function
Source:
src/input/SinglePad.js line 53

onFloatCallback : function

This callback is invoked every time a button is changed to a value where value > 0 and value < 1.

Type:
  • function
Source:
src/input/SinglePad.js line 68

onUpCallback : function

This callback is invoked every time a gamepad button is released.

Type:
  • function
Source:
src/input/SinglePad.js line 58

Methods

addCallbacks(context, callbacks)

Add callbacks to this Gamepad to handle connect / disconnect / button down / button up / axis change / float value buttons.

Parameters:
Name Type Description
context object

The context under which the callbacks are run.

callbacks object

Object that takes six different callbak methods: onConnectCallback, onDisconnectCallback, onDownCallback, onUpCallback, onAxisCallback, onFloatCallback

Source:
src/input/SinglePad.js line 120

axis(axisCode)

Returns value of requested axis.

Parameters:
Name Type Description
axisCode number

The index of the axis to check

Source:
src/input/SinglePad.js line 422
Returns:

Axis value if available otherwise false

Type
number

buttonValue(buttonCode)

Returns the value of a gamepad button. Intended mainly for cases when you have floating button values, for example analog trigger buttons on the XBOX 360 controller.

Parameters:
Name Type Description
buttonCode number

The buttonCode of the button to check.

Source:
src/input/SinglePad.js line 505
Returns:

Button value if available otherwise null. Be careful as this can incorrectly evaluate to 0.

Type
number

connect(rawPad)

Gamepad connect function, should be called by Phaser.Gamepad.

Parameters:
Name Type Description
rawPad object

The raw gamepad object

Source:
src/input/SinglePad.js line 213

destroy()

Destroys this object and associated callback references.

Source:
src/input/SinglePad.js line 293

disconnect()

Gamepad disconnect function, should be called by Phaser.Gamepad.

Source:
src/input/SinglePad.js line 256

getButton(buttonCode)

Gets a DeviceButton object from this controller to be stored and referenced locally. The DeviceButton object can then be polled, have events attached to it, etc.

Parameters:
Name Type Description
buttonCode number

The buttonCode of the button, i.e. Phaser.Gamepad.BUTTON_0, Phaser.Gamepad.XBOX360_A, etc.

Source:
src/input/SinglePad.js line 143
Returns:

The DeviceButton object which you can store locally and reference directly.

Type
Phaser.DeviceButton

isDown(buttonCode)

Returns true if the button is pressed down.

Parameters:
Name Type Description
buttonCode number

The buttonCode of the button to check.

Source:
src/input/SinglePad.js line 439
Returns:

True if the button is pressed down.

Type
boolean

isUp(buttonCode)

Returns true if the button is not currently pressed.

Parameters:
Name Type Description
buttonCode number

The buttonCode of the button to check.

Source:
src/input/SinglePad.js line 456
Returns:

True if the button is not currently pressed down.

Type
boolean

justPressed(buttonCode [, duration])

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

Parameters:
Name Type Argument Default Description
buttonCode number

The buttonCode of the button to check for.

duration number <optional>
250

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

Source:
src/input/SinglePad.js line 489
Returns:

True if the button is just pressed otherwise false.

Type
boolean

justReleased(buttonCode [, duration])

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

Parameters:
Name Type Argument Default Description
buttonCode number

The buttonCode of the button to check for.

duration number <optional>
250

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

Source:
src/input/SinglePad.js line 473
Returns:

True if the button is just released otherwise false.

Type
boolean

pollStatus()

Main update function called by Phaser.Gamepad.

Source:
src/input/SinglePad.js line 163

processAxisChange(axisState)

Handles changes in axis.

Parameters:
Name Type Description
axisState object

State of the relevant axis

Source:
src/input/SinglePad.js line 321

processButtonDown(buttonCode, value)

Handles button down press.

Parameters:
Name Type Description
buttonCode number

Which buttonCode of this button

value object

Button value

Source:
src/input/SinglePad.js line 347

processButtonFloat(buttonCode, value)

Handles buttons with floating values (like analog buttons that acts almost like an axis but still registers like a button)

Parameters:
Name Type Description
buttonCode number

Which buttonCode of this button

value object

Button value (will range somewhere between 0 and 1, but not specifically 0 or 1.

Source:
src/input/SinglePad.js line 397

processButtonUp(buttonCode, value)

Handles button release.

Parameters:
Name Type Description
buttonCode number

Which buttonCode of this button

value object

Button value

Source:
src/input/SinglePad.js line 372

reset()

Reset all buttons/axes of this gamepad.

Source:
src/input/SinglePad.js line 523

phaser-ce@2.20.1 is on GitHub and NPM

Documentation generated by JSDoc 3.6.11 on 2024-10-05 using Tomorrow.