Phaser. Gamepad

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

Source - input/Gamepad.js, line 486

callbackContext :object

The context under which the callbacks are run.

Source - input/Gamepad.js, line 80

enabled :boolean

Gamepad input will only be processed if enabled.

Default Value:
  • true
Source - input/Gamepad.js, line 52

game :Phaser.Game

Local reference to game.

Source - input/Gamepad.js, line 26

onAxisCallback :function

This callback is invoked every time any gamepad axis is changed.

Source - input/Gamepad.js, line 105

onConnectCallback :function

This callback is invoked every time any gamepad is connected

Source - input/Gamepad.js, line 85

onDisconnectCallback :function

This callback is invoked every time any gamepad is disconnected

Source - input/Gamepad.js, line 90

onDownCallback :function

This callback is invoked every time any gamepad button is pressed down.

Source - input/Gamepad.js, line 95

onFloatCallback :function

This callback is invoked every time any gamepad button is changed to a value where value > 0 and value < 1.

Source - input/Gamepad.js, line 110

onUpCallback :function

This callback is invoked every time any gamepad button is released.

Source - input/Gamepad.js, line 100

<readonly> pad1 :Phaser.SinglePad

Gamepad #1

Source - input/Gamepad.js, line 528

<readonly> pad2 :Phaser.SinglePad

Gamepad #2

Source - input/Gamepad.js, line 542

<readonly> pad3 :Phaser.SinglePad

Gamepad #3

Source - input/Gamepad.js, line 556

<readonly> pad4 :Phaser.SinglePad

Gamepad #4

Source - input/Gamepad.js, line 570

<readonly> padsConnected :number

How many live gamepads are currently connected.

Source - input/Gamepad.js, line 514

<readonly> supported :boolean

Whether or not gamepads are supported in current browser.

Source - input/Gamepad.js, line 500

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 - input/Gamepad.js, line 139

destroy()

Destroys this object and the associated event listeners.

Source - input/Gamepad.js, line 466

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:
boolean -

True if a button is currently down.

Source - input/Gamepad.js, line 447

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:
boolean -

True if the button is just pressed otherwise false.

Source - input/Gamepad.js, line 405

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:
boolean -

True if the button is just released otherwise false.

Source - input/Gamepad.js, line 426

reset()

Reset all buttons/axes of all gamepads

Source - input/Gamepad.js, line 390

setDeadZones()

Sets the deadZone variable for all four gamepads

Source - input/Gamepad.js, line 363

start()

Starts the Gamepad event handling. This MUST be called manually before Phaser will start polling the Gamepad API.

Source - input/Gamepad.js, line 162

stop()

Stops the Gamepad event handling.

Source - input/Gamepad.js, line 376

<internal> update()

Main gamepad update loop. Should not be called manually.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - input/Gamepad.js, line 231
Phaser Copyright © 2012-2015 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.2 on Thu Feb 18 2016 14:41:02 GMT+0000 (GMT Standard Time) using the DocStrap template.