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
- Source code: input/SinglePad.js (Line 38)
- Source code: input/SinglePad.js (Line 33)
- Source code: input/SinglePad.js (Line 73)
- Source code: input/SinglePad.js (Line 21)
- Source code: input/SinglePad.js (Line 27)
- Source code: input/SinglePad.js (Line 63)
- Source code: input/SinglePad.js (Line 43)
- Source code: input/SinglePad.js (Line 48)
- Source code: input/SinglePad.js (Line 53)
- Source code: input/SinglePad.js (Line 68)
- Source code: input/SinglePad.js (Line 58)
callbackContext : Object
The context under which the callbacks are run.
[readonly] connected : boolean
Whether or not this particular gamepad is connected or not.
deadZone : number
Dead zone for axis feedback - within this value you won't trigger updates.
game : Phaser.Game
Local reference to game.
[readonly] index : number
The gamepad index as per browsers data
onAxisCallback : Function
This callback is invoked every time an axis is changed.
onConnectCallback : Function
This callback is invoked every time this gamepad is connected
onDisconnectCallback : Function
This callback is invoked every time this gamepad is disconnected
onDownCallback : Function
This callback is invoked every time a button is pressed down.
onFloatCallback : Function
This callback is invoked every time a button is changed to a value where value > 0 and value < 1.
onUpCallback : Function
This callback is invoked every time a gamepad button is released.
Public Methods
- Source code: input/SinglePad.js (Line 121)
- Source code: input/SinglePad.js (Line 432)
- Source code: input/SinglePad.js (Line 520)
- Source code: input/SinglePad.js (Line 216)
- Source code: input/SinglePad.js (Line 298)
- Source code: input/SinglePad.js (Line 260)
- Source code: input/SinglePad.js (Line 144)
- Source code: input/SinglePad.js (Line 450)
- Source code: input/SinglePad.js (Line 468)
- Source code: input/SinglePad.js (Line 503)
- Source code: input/SinglePad.js (Line 486)
- Source code: input/SinglePad.js (Line 165)
- Source code: input/SinglePad.js (Line 327)
- Source code: input/SinglePad.js (Line 354)
- Source code: input/SinglePad.js (Line 406)
- Source code: input/SinglePad.js (Line 380)
- Source code: input/SinglePad.js (Line 539)
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: |
axis(axisCode) → {number}
Returns value of requested axis.
Parameters
Name | Type | Description |
---|---|---|
axisCode | number | The index of the axis to check |
Returns
Axis value if available otherwise false
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
Button value if available otherwise null. Be careful as this can incorrectly evaluate to 0.
connect(rawPad)
Gamepad connect function, should be called by Phaser.Gamepad.
Parameters
Name | Type | Description |
---|---|---|
rawPad | object | The raw gamepad object |
destroy()
Destroys this object and associated callback references.
disconnect()
Gamepad disconnect function, should be called by Phaser.Gamepad.
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.
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
True if the button is pressed down.
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
True if the button is not currently pressed down.
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
True if the button is just pressed otherwise false.
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
True if the button is just released otherwise false.
pollStatus()
Main update function called by Phaser.Gamepad.
processAxisChange(axisState)
Handles changes in axis.
Parameters
Name | Type | Description |
---|---|---|
axisState | object | State of the relevant axis |
processButtonDown(buttonCode, value)
Handles button down press.
Parameters
Name | Type | Description |
---|---|---|
buttonCode | number | Which buttonCode of this button |
value | object | Button value |
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. |
processButtonUp(buttonCode, value)
Handles button release.
Parameters
Name | Type | Description |
---|---|---|
buttonCode | number | Which buttonCode of this button |
value | object | Button value |
reset()
Reset all buttons/axes of this gamepad.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.SinglePad.html