# Class: Gamepad

## Phaser. Gamepad

Phaser.Gamepad

#### new Gamepad(game)

  The Gamepad class handles looking after gamepad input for your game. Remember to call gamepad.start(); expecting input!

  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 20

### Members

#### <readonly> active

  If the gamepad input is active or not - if not active it should not be updated from Input.js

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `active` | boolean | If the gamepad input is active or not.

  Source:
    - input/Gamepad.js, line 433

#### callbackContext

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `callbackContext` | Object | The context under which the callbacks are run.

  Source:
    - input/Gamepad.js, line 90

#### disabled

  You can disable all Gamepad Input by setting disabled to true. While true all new input related events will be ignored.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `disabled` | boolean | The disabled state of the Gamepad.

  Default Value:
    - false
  Source:
    - input/Gamepad.js, line 62

#### game

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | Local reference to game.

  Source:
    - input/Gamepad.js, line 25

#### onAxisCallback

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onAxisCallback` | function | This callback is invoked every time any gamepad axis is changed.

  Source:
    - input/Gamepad.js, line 115

#### onConnectCallback

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onConnectCallback` | function | This callback is invoked every time any gamepad is connected

  Source:
    - input/Gamepad.js, line 95

#### onDisconnectCallback

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onDisconnectCallback` | function | This callback is invoked every time any gamepad is disconnected

  Source:
    - input/Gamepad.js, line 100

#### onDownCallback

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onDownCallback` | function | This callback is invoked every time any gamepad button is pressed down.

  Source:
    - input/Gamepad.js, line 105

#### onFloatCallback

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `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 120

#### onUpCallback

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onUpCallback` | function | This callback is invoked every time any gamepad button is released.

  Source:
    - input/Gamepad.js, line 110

#### <readonly> pad1

  Gamepad #1

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `pad1` | boolean | Gamepad #1;

  Source:
    - input/Gamepad.js, line 475

#### <readonly> pad2

  Gamepad #2

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `pad2` | boolean | Gamepad #2

  Source:
    - input/Gamepad.js, line 489

#### <readonly> pad3

  Gamepad #3

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `pad3` | boolean | Gamepad #3

  Source:
    - input/Gamepad.js, line 503

#### <readonly> pad4

  Gamepad #4

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `pad4` | boolean | Gamepad #4

  Source:
    - input/Gamepad.js, line 517

#### <readonly> padsConnected

  How many live gamepads are currently connected.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `padsConnected` | boolean | How many live gamepads are currently connected.

  Source:
    - input/Gamepad.js, line 461

#### <readonly> supported

  Whether or not gamepads are supported in current browser.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `supported` | boolean | Whether or not gamepads are supported in current browser.

  Source:
    - input/Gamepad.js, line 447

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

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

  Source:
    - input/Gamepad.js, line 410

  ##### Returns:

  True if a button is currently down.

  Type
    boolean

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

  Source:
    - input/Gamepad.js, line 368

  ##### Returns:

  True if the button is just pressed otherwise false.

  Type
    boolean

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

  Source:
    - input/Gamepad.js, line 389

  ##### Returns:

  True if the button is just released otherwise false.

  Type
    boolean

#### reset()

  Reset all buttons/axes of all gamepads

  Source:
    - input/Gamepad.js, line 353

#### setDeadZones()

  Sets the deadZone variable for all four gamepads

  Source:
    - input/Gamepad.js, line 326

#### start()

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

  Source:
    - input/Gamepad.js, line 158

#### stop()

  Stops the Gamepad event handling.

  Source:
    - input/Gamepad.js, line 339