Class: Phaser.Gamepad
Constructor
new Gamepad(game)
The Gamepad class handles gamepad input and dispatches gamepad events.
Remember to call gamepad.start()
.
HTML5 GAMEPAD API SUPPORT IS AT AN EXPERIMENTAL STAGE!
At moment of writing this (end of 2013) only Chrome supports parts of it out of the box. Firefox supports it
via prefs flags (about:config, search gamepad). The browsers map the same controllers differently.
This class has constants for Windows 7 Chrome mapping of XBOX 360 controller.
Parameters
Name | Type | Description |
---|---|---|
game | Phaser.Game | A reference to the currently running game. |
- Source code: input/Gamepad.js (Line 21)
Public Properties
- Source code: input/Gamepad.js (Line 496)
- Source code: input/Gamepad.js (Line 80)
- Default Value
- true
- Source code: input/Gamepad.js (Line 52)
- Source code: input/Gamepad.js (Line 26)
- Source code: input/Gamepad.js (Line 105)
- Source code: input/Gamepad.js (Line 85)
- Source code: input/Gamepad.js (Line 90)
- Source code: input/Gamepad.js (Line 95)
- Source code: input/Gamepad.js (Line 110)
- Source code: input/Gamepad.js (Line 100)
- Source code: input/Gamepad.js (Line 538)
- Source code: input/Gamepad.js (Line 552)
- Source code: input/Gamepad.js (Line 566)
- Source code: input/Gamepad.js (Line 580)
- Source code: input/Gamepad.js (Line 524)
- Source code: input/Gamepad.js (Line 510)
[readonly] active : boolean
If the gamepad input is active or not - if not active it should not be updated from Input.js
callbackContext : Object
The context under which the callbacks are run.
enabled : boolean
Gamepad input will only be processed if enabled.
game : Phaser.Game
Local reference to game.
onAxisCallback : Function
This callback is invoked every time any gamepad axis is changed.
onConnectCallback : Function
This callback is invoked every time any gamepad is connected
onDisconnectCallback : Function
This callback is invoked every time any gamepad is disconnected
onDownCallback : Function
This callback is invoked every time any gamepad button is pressed down.
onFloatCallback : Function
This callback is invoked every time any gamepad button is changed to a value where value > 0 and value < 1.
onUpCallback : Function
This callback is invoked every time any gamepad button is released.
[readonly] pad1 : Phaser.SinglePad
Gamepad #1
[readonly] pad2 : Phaser.SinglePad
Gamepad #2
[readonly] pad3 : Phaser.SinglePad
Gamepad #3
[readonly] pad4 : Phaser.SinglePad
Gamepad #4
[readonly] padsConnected : number
How many live gamepads are currently connected.
[readonly] supported : boolean
Whether or not gamepads are supported in current browser.
Public Methods
- Source code: input/Gamepad.js (Line 139)
- Source code: input/Gamepad.js (Line 476)
- Source code: input/Gamepad.js (Line 457)
- Source code: input/Gamepad.js (Line 436)
- Source code: input/Gamepad.js (Line 415)
- Source code: input/Gamepad.js (Line 400)
- Source code: input/Gamepad.js (Line 373)
- Source code: input/Gamepad.js (Line 162)
- Source code: input/Gamepad.js (Line 386)
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source code: input/Gamepad.js (Line 231)
addCallbacks(context, callbacks)
Add callbacks to the main Gamepad handler 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 callback methods: |
destroy()
Destroys this object and the associated event listeners.
isDown(buttonCode) → {boolean}
Returns true if the button is currently pressed down, on ANY gamepad.
Parameters
Name | Type | Description |
---|---|---|
buttonCode | number | The buttonCode of the button to check for. |
Returns
True if a button is currently down.
justPressed(buttonCode, duration) → {boolean}
Returns the "just released" state of a button from ANY gamepad connected. 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.
justPressed(buttonCode, duration) → {boolean}
Returns the "just pressed" state of a button from ANY gamepad connected. 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.
reset()
Reset all buttons/axes of all gamepads
setDeadZones()
Sets the deadZone variable for all four gamepads
start()
Starts the Gamepad event handling.
This MUST be called manually before Phaser will start polling the Gamepad API.
stop()
Stops the Gamepad event handling.
<internal> update()
Main gamepad update loop. Should not be called manually.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Gamepad.html