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 - input/SinglePad.js, line 16
Members
-
callbackContext :object
-
The context under which the callbacks are run.
- Source - input/SinglePad.js, line 38
-
<readonly> connected :boolean
-
Whether or not this particular gamepad is connected or not.
- Source - input/SinglePad.js, line 33
-
deadZone :number
-
Dead zone for axis feedback - within this value you won't trigger updates.
- Source - input/SinglePad.js, line 73
-
game :Phaser.Game
-
Local reference to game.
- Source - input/SinglePad.js, line 21
-
<readonly> index :number
-
The gamepad index as per browsers data
- Source - input/SinglePad.js, line 27
-
onAxisCallback :function
-
This callback is invoked every time an axis is changed.
- Source - input/SinglePad.js, line 63
-
onConnectCallback :function
-
This callback is invoked every time this gamepad is connected
- Source - input/SinglePad.js, line 43
-
onDisconnectCallback :function
-
This callback is invoked every time this gamepad is disconnected
- Source - input/SinglePad.js, line 48
-
onDownCallback :function
-
This callback is invoked every time a button is pressed down.
- Source - 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 - input/SinglePad.js, line 68
-
onUpCallback :function
-
This callback is invoked every time a gamepad button is released.
- Source - 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 - 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 - input/SinglePad.js, line 431
-
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 - input/SinglePad.js, line 519
-
connect(rawPad)
-
Gamepad connect function, should be called by Phaser.Gamepad.
Parameters:
Name Type Description rawPad
object The raw gamepad object
- Source - input/SinglePad.js, line 215
-
destroy()
-
Destroys this object and associated callback references.
- Source - input/SinglePad.js, line 297
-
disconnect()
-
Gamepad disconnect function, should be called by Phaser.Gamepad.
- Source - input/SinglePad.js, line 259
-
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 - input/SinglePad.js, line 143
-
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 - input/SinglePad.js, line 449
-
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 - input/SinglePad.js, line 467
-
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 - input/SinglePad.js, line 502
-
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 - input/SinglePad.js, line 485
-
pollStatus()
-
Main update function called by Phaser.Gamepad.
- Source - input/SinglePad.js, line 164
-
processAxisChange(axisState)
-
Handles changes in axis.
Parameters:
Name Type Description axisState
object State of the relevant axis
- Source - input/SinglePad.js, line 326
-
processButtonDown(buttonCode, value)
-
Handles button down press.
Parameters:
Name Type Description buttonCode
number Which buttonCode of this button
value
object Button value
- Source - input/SinglePad.js, line 353
-
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 - input/SinglePad.js, line 405
-
processButtonUp(buttonCode, value)
-
Handles button release.
Parameters:
Name Type Description buttonCode
number Which buttonCode of this button
value
object Button value
- Source - input/SinglePad.js, line 379
-
reset()
-
Reset all buttons/axes of this gamepad.
- Source - input/SinglePad.js, line 538