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

_index

Properties:
Name Type Description
index number

The gamepad index as per browsers data

Default Value:
  • null
Source:

_padParent

Properties:
Name Type Description
padParent Phaser.Gamepad

Main Phaser Gamepad object

Source:

callbackContext

Properties:
Name Type Description
callbackContext Object

The context under which the callbacks are run.

Source:

<readonly> connected

Whether or not this particular gamepad is connected or not.

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

Gamepad index as per browser data

Properties:
Name Type Description
index number

The gamepad index, used to identify specific gamepads in the browser

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}

If you need more fine-grained control over a Key you can create a new Phaser.Key object via this method. The Key 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 or Phaser.Gamepad.BUTTON_1

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:

buttonValue(buttonCode) → {boolean}

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 false.

Type
boolean

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:

isDown(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

isDown(buttonCode) → {boolean}

Returns true if the button is currently pressed down.

Parameters:
Name Type Description
buttonCode number

The buttonCode of the key to check.

Source:
Returns:

True if the key is currently down.

Type
boolean

justPressed(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

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

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 Mon Feb 24 2014 01:12:30 GMT-0000 (GMT) using the DocStrap template.