Class: Phaser.SinglePad

Constructor

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 code: input/SinglePad.js (Line 16)

Public Properties

callbackContext : Object

The context under which the callbacks are run.

Source code: input/SinglePad.js (Line 38)

[readonly] connected : boolean

Whether or not this particular gamepad is connected or not.

Source code: input/SinglePad.js (Line 33)

deadZone : number

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

Source code: input/SinglePad.js (Line 73)

game : Phaser.Game

Local reference to game.

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

[readonly] index : number

The gamepad index as per browsers data

Source code: input/SinglePad.js (Line 27)

onAxisCallback : Function

This callback is invoked every time an axis is changed.

Source code: input/SinglePad.js (Line 63)

onConnectCallback : Function

This callback is invoked every time this gamepad is connected

Source code: input/SinglePad.js (Line 43)

onDisconnectCallback : Function

This callback is invoked every time this gamepad is disconnected

Source code: input/SinglePad.js (Line 48)

onDownCallback : Function

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

Source code: 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.

Source code: input/SinglePad.js (Line 68)

onUpCallback : Function

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

Source code: input/SinglePad.js (Line 58)

Public 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 code: input/SinglePad.js (Line 121)

axis(axisCode) → {number}

Returns value of requested axis.

Parameters
Name Type Description
axisCode number

The index of the axis to check

Returns
number -

Axis value if available otherwise false

Source code: input/SinglePad.js (Line 432)

buttonValue(buttonCode) → {number}

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.

Returns
number -

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

Source code: input/SinglePad.js (Line 520)

connect(rawPad)

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

Parameters
Name Type Description
rawPad object

The raw gamepad object

Source code: input/SinglePad.js (Line 216)

destroy()

Destroys this object and associated callback references.

Source code: input/SinglePad.js (Line 298)

disconnect()

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

Source code: input/SinglePad.js (Line 260)

getButton(buttonCode) → {Phaser.DeviceButton}

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.

Returns

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

Source code: input/SinglePad.js (Line 144)

isDown(buttonCode) → {boolean}

Returns true if the button is pressed down.

Parameters
Name Type Description
buttonCode number

The buttonCode of the button to check.

Returns
boolean -

True if the button is pressed down.

Source code: input/SinglePad.js (Line 450)

isUp(buttonCode) → {boolean}

Returns true if the button is not currently pressed.

Parameters
Name Type Description
buttonCode number

The buttonCode of the button to check.

Returns
boolean -

True if the button is not currently pressed down.

Source code: input/SinglePad.js (Line 468)

justPressed(buttonCode, duration) → {boolean}

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.

Returns
boolean -

True if the button is just pressed otherwise false.

Source code: input/SinglePad.js (Line 503)

justReleased(buttonCode, duration) → {boolean}

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.

Returns
boolean -

True if the button is just released otherwise false.

Source code: input/SinglePad.js (Line 486)

pollStatus()

Main update function called by Phaser.Gamepad.

Source code: input/SinglePad.js (Line 165)

processAxisChange(axisState)

Handles changes in axis.

Parameters
Name Type Description
axisState object

State of the relevant axis

Source code: input/SinglePad.js (Line 327)

processButtonDown(buttonCode, value)

Handles button down press.

Parameters
Name Type Description
buttonCode number

Which buttonCode of this button

value object

Button value

Source code: input/SinglePad.js (Line 354)

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 code: input/SinglePad.js (Line 406)

processButtonUp(buttonCode, value)

Handles button release.

Parameters
Name Type Description
buttonCode number

Which buttonCode of this button

value object

Button value

Source code: input/SinglePad.js (Line 380)

reset()

Reset all buttons/axes of this gamepad.

Source code: input/SinglePad.js (Line 539)

© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.SinglePad.html