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:
- src/input/Gamepad.js line 21
Members
-
<readonly> active : boolean
-
If the gamepad input is active or not - if not active it should not be updated from Input.js
Type:
- boolean
- Source:
- src/input/Gamepad.js line 512
-
callbackContext : object
-
The context under which the callbacks are run.
Type:
- object
- Source:
- src/input/Gamepad.js line 81
-
enabled : boolean
-
Gamepad input will only be processed if enabled.
Type:
- boolean
- Default Value:
-
- true
- Source:
- src/input/Gamepad.js line 53
-
game : Phaser.Game
-
Local reference to game.
Type:
- Source:
- src/input/Gamepad.js line 27
-
onAxisCallback : function
-
This callback is invoked every time any gamepad axis is changed.
Type:
- function
- Source:
- src/input/Gamepad.js line 106
-
onConnectCallback : function
-
This callback is invoked every time any gamepad is connected
Type:
- function
- Source:
- src/input/Gamepad.js line 86
-
onDisconnectCallback : function
-
This callback is invoked every time any gamepad is disconnected
Type:
- function
- Source:
- src/input/Gamepad.js line 91
-
onDownCallback : function
-
This callback is invoked every time any gamepad button is pressed down.
Type:
- function
- Source:
- src/input/Gamepad.js line 96
-
onFloatCallback : function
-
This callback is invoked every time any gamepad button is changed to a value where value > 0 and value < 1.
Type:
- function
- Source:
- src/input/Gamepad.js line 111
-
onUpCallback : function
-
This callback is invoked every time any gamepad button is released.
Type:
- function
- Source:
- src/input/Gamepad.js line 101
-
<readonly> pad1 : Phaser.SinglePad
-
Gamepad #1
Type:
- Source:
- src/input/Gamepad.js line 557
-
<readonly> pad2 : Phaser.SinglePad
-
Gamepad #2
Type:
- Source:
- src/input/Gamepad.js line 572
-
<readonly> pad3 : Phaser.SinglePad
-
Gamepad #3
Type:
- Source:
- src/input/Gamepad.js line 587
-
<readonly> pad4 : Phaser.SinglePad
-
Gamepad #4
Type:
- Source:
- src/input/Gamepad.js line 602
-
<readonly> padsConnected : number
-
How many live gamepads are currently connected.
Type:
- number
- Source:
- src/input/Gamepad.js line 542
-
<readonly> supported : boolean
-
Whether or not gamepads are supported in current browser.
Type:
- boolean
- Source:
- src/input/Gamepad.js line 527
Methods
-
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: onConnectCallback, onDisconnectCallback, onDownCallback, onUpCallback, onAxisCallback, onFloatCallback
- Source:
- src/input/Gamepad.js line 140
-
destroy()
-
Destroys this object and the associated event listeners.
- Source:
- src/input/Gamepad.js line 491
-
isDown(buttonCode)
-
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.
- Source:
- src/input/Gamepad.js line 471
Returns:
True if a button is currently down.
- Type
- boolean
-
justPressed(buttonCode [, duration])
-
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.
- Source:
- src/input/Gamepad.js line 427
Returns:
True if the button is just pressed otherwise false.
- Type
- boolean
-
justPressed(buttonCode [, duration])
-
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.
- Source:
- src/input/Gamepad.js line 449
Returns:
True if the button is just released otherwise false.
- Type
- boolean
-
reset()
-
Reset all buttons/axes of all gamepads
- Source:
- src/input/Gamepad.js line 411
-
setDeadZones()
-
Sets the deadZone variable for all four gamepads
- Source:
- src/input/Gamepad.js line 382
-
start()
-
Starts the Gamepad event handling. This MUST be called manually before Phaser will start polling the Gamepad API.
- Source:
- src/input/Gamepad.js line 164
-
stop()
-
Stops the Gamepad event handling.
- Source:
- src/input/Gamepad.js line 396
-
<protected> update()
-
Main gamepad update loop. Should not be called manually.
- Source:
- src/input/Gamepad.js line 238