Class: SinglePad

Phaser. SinglePad

A single Phaser Gamepad

new SinglePad(game, padParent)

Parameters:
Name Type Description
game Phaser.Game

Current game instance.

padParent Object

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

Source:

Members

callbackContext

Properties:
Name Type Description
callbackContext Object

The context under which the callbacks are run.

Source:

<readonly> connected

Properties:
Name Type Description
connected boolean

Whether or not this particular gamepad is connected or not.

Source:

deadZone

Properties:
Name Type Description
deadZone number

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

Source:

game

Properties:
Name Type Description
game Phaser.Game

Local reference to game.

Source:

<readonly> index

Properties:
Name Type Description
index number

The gamepad index as per browsers data

Source:

onAxisCallback

Properties:
Name Type Description
onAxisCallback function

This callback is invoked every time an axis is changed.

Source:

onConnectCallback

Properties:
Name Type Description
onConnectCallback function

This callback is invoked every time this gamepad is connected

Source:

onDisconnectCallback

Properties:
Name Type Description
onDisconnectCallback function

This callback is invoked every time this gamepad is disconnected

Source:

onDownCallback

Properties:
Name Type Description
onDownCallback function

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

Source:

onFloatCallback

Properties:
Name Type Description
onFloatCallback function

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

Source:

onUpCallback

Properties:
Name Type Description
onUpCallback function

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

Source:

Methods

addButton(buttonCode) → {Phaser.GamepadButton}

DEPRECATED: Please see SinglePad.getButton for the same functionality.

If you need more fine-grained control over a gamepad button you can create a new Phaser.GamepadButton object via this method. The GamepadButton 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:
Returns:

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

Type
Phaser.GamepadButton

addCallbacks(context, callbacks)

Add callbacks to the 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:

axis(axisCode) → {number}

Returns value of requested axis.

Parameters:
Name Type Description
axisCode number

The index of the axis to check

Source:
Returns:

Axis value if available otherwise false

Type
number

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.

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

disconnect()

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

Source:

getButton(buttonCode) → {Phaser.GamepadButton}

Gets a GamepadButton object from this controller to be stored and referenced locally. The GamepadButton 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:
Returns:

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

Type
Phaser.GamepadButton

isDown(buttonCode) → {boolean}

Returns true if the button is pressed down.

Parameters:
Name Type Description
buttonCode number

The buttonCode of the button to check.

Source:
Returns:

True if the button is pressed down.

Type
boolean

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.

Source:
Returns:

True if the button is not currently pressed down.

Type
boolean

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.

Source:
Returns:

True if the button is just pressed otherwise false.

Type
boolean

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.

Source:
Returns:

True if the button is just released otherwise false.

Type
boolean

pollStatus()

Main update function, should be called by Phaser.Gamepad.

Source:

processAxisChange(axisState)

Handles changes in axis.

Parameters:
Name Type Description
axisState Object

State of the relevant axis

Source:

processButtonDown(buttonCode, value)

Handles button down press.

Parameters:
Name Type Description
buttonCode number

Which buttonCode of this button

value Object

Button value

Source:

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:

processButtonUp(buttonCode, value)

Handles button release.

Parameters:
Name Type Description
buttonCode number

Which buttonCode of this button

value Object

Button value

Source:

reset()

Reset all buttons/axes of this gamepad.

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Thu Jul 10 2014 20:19:13 GMT+0100 (BST) using the DocStrap template.