API Docs for: 0.0.1
Show:

Gamepad Class

Defined in: gamepad.js:284
Module: Gamepad

Provides simple interface and multi-platform support for the gamepad API.

You can change the deadzone and maximizeThreshold parameters to suit your taste but the defaults should generally work fine.

Constructor

Gamepad

(
  • [updateStrategy]
)

Defined in gamepad.js:284

Parameters:

Methods

_addAxisUpdater

(
  • gamepad
  • mapping
  • index
)
private

Defined in gamepad.js:729

Adds an updater for an axis control

Parameters:

  • gamepad Object

    the gamepad for which to create the updater

  • mapping Object

    the mapping on which to work on

  • index Number

    axis index

_addButtonUpdater

(
  • gamepad
  • mapping
  • index
)
private

Defined in gamepad.js:683

Adds an updater for a button control

Parameters:

  • gamepad Object

    the gamepad for which to create the updater

  • mapping Object

    the mapping on which to work on

  • index Number

    button index

_applyDeadzoneMaximize

(
  • value
  • [deadzone]
  • [maximizeThreshold]
)
private

Defined in gamepad.js:1014

Applies deadzone and maximization.

You can change the thresholds via deadzone and maximizeThreshold members.

Parameters:

  • value Number

    Value to modify

  • [deadzone] Number optional

    Deadzone to apply

  • [maximizeThreshold] Number optional

    From which value to maximize value

_connect

(
  • gamepad
)
private

Defined in gamepad.js:651

Registers given gamepad.

Parameters:

  • gamepad Object

    Gamepad to connect to

_createAxisGetter

(
  • gamepad
  • axes
  • index
)
Function private

Defined in gamepad.js:859

Creates a getter according to the mapping entry for the specific index. Currently supported entries:

axes.byAxis[index]: Number := Index into gamepad.axes; -1 ignored

Parameters:

  • gamepad Object

    the gamepad for which to create a getter

  • axes Object

    the mappings entry for the axes

  • index Number

    the specific axis entry

Returns:

Function:

a getter returning the value for the requested axis

_createButtonGetter

(
  • gamepad
  • buttons
  • index
)
Function private

Defined in gamepad.js:781

Creates a getter according to the mapping entry for the specific index. Currently supported entries:

buttons.byButton[index]: Number := Index into gamepad.buttons; -1 tests byAxis buttons.byAxis[index]: Array := [Index into gamepad.axes; Zero Value, One Value]

Parameters:

  • gamepad Object

    the gamepad for which to create a getter

  • buttons Object

    the mappings entry for the buttons

  • index Number

    the specific button entry

Returns:

Function:

a getter returning the value for the requested button

_disconnect

(
  • gamepad
)
private

Defined in gamepad.js:897

Disconnects from given gamepad.

Parameters:

  • gamepad Object

    Gamepad to disconnect

_fire

(
  • event
  • data
)
private

Defined in gamepad.js:605

Fires an internal event with given data.

Parameters:

  • event String

    Event to fire, one of Gamepad.Event..

  • data

    Data to pass to the listener

_fireAxisChangedEvent

(
  • gamepad
  • controlName
  • value
)
private

Defined in gamepad.js:763

Fires an AXIS_CHANGED event

Parameters:

  • gamepad Object

    the gamepad to notify for

  • controlName String

    name of the control that changes its value

  • value Number

    the new value

_resolveControllerType

(
  • id
)
String private

Defined in gamepad.js:923

Resolves controller type from its id.

Parameters:

  • id String

    Controller id

Returns:

String:

Controller type, one of Gamepad.Type

_resolveMapping

(
  • gamepad
)
Object private

Defined in gamepad.js:946

Parameters:

  • gamepad Object

    the gamepad for which to resolve the mapping

Returns:

Object:

a mapping object for the given gamepad

_update

() private

Defined in gamepad.js:992

Updates the controllers, triggering TICK events.

bind

(
  • event
  • listener
)
Gamepad

Defined in gamepad.js:538

Binds a listener to a gamepad event.

Parameters:

  • event String

    Event to bind to, one of Gamepad.Event..

  • listener Function

    Listener to call when given event occurs

Returns:

Gamepad:

Self

count

() Number

Defined in gamepad.js:595

Returns the number of connected gamepads.

Returns:

Number:

envMatchesFilter

(
  • filter
  • env
)
Boolean static

Defined in gamepad.js:972

Parameters:

  • filter Object

    the filter object describing properties to match

  • env Object

    the environment object that is matched against filter

Returns:

Boolean:

true if env is covered by filter

getNullPlatform

() Object static

Defined in gamepad.js:623

Returns:

Object:

a platform that does not support anything

init

() Boolean

Defined in gamepad.js:518

Initializes the gamepad.

You usually want to bind to the events first and then initialize it.

Returns:

Boolean:

true if a supporting platform was detected, false otherwise.

resolvePlatform

(
  • listener
)
Object static

Defined in gamepad.js:632

Resolves platform.

Parameters:

  • listener Object

    the listener to handle _connect() or _disconnect() calls

Returns:

Object:

A platform instance

unbind

(
  • [type]
  • [listener]
)
Boolean

Defined in gamepad.js:556

Removes listener of given type.

If no type is given, all listeners are removed. If no listener is given, all listeners of given type are removed.

Parameters:

  • [type] String optional

    Type of listener to remove

  • [listener] Function optional

    The listener function to remove

Returns:

Boolean:

Was unbinding the listener successful

Properties

Mappings

Unknown

Defined in gamepad.js:460

Mapping of various gamepads that differ from the standard mapping on different platforms too unify their buttons and axes.

Each mapping should have an 'env' object, which describes the environment in which the mapping is active. The more entries such an environment has, the more specific it is.

Mappings are expressed for both buttons and axes. Buttons might refer to axes if they are notified as such.

PlatformFactories

Array

Defined in gamepad.js:317

List of factories of supported platforms. Currently available platforms: WebKitPlatform, FirefoxPlatform,

StandardAxes

Unknown

Defined in gamepad.js:432

List of standard axis names. The index is the according standard axis index as per standard.

StandardButtons

Unknown

Defined in gamepad.js:418

List of standard button names. The index is the according standard button index as per standard.

StandardMapping

Unknown

Defined in gamepad.js:444

The standard mapping that represents the mapping as per definition. Each button and axis map to the same index.

Type

Unknown

Defined in gamepad.js:326

List of supported controller types.

Sub-properties:

  • PLAYSTATION String

    Playstation controller

  • LOGITECH String

    Logitech controller

  • XBOX String

    XBOX controller

  • UNKNOWN String

    Unknown controller

UpdateStrategies

Unknown

Defined in gamepad.js:306

The available update strategies

Sub-properties:

Events

axis-changed

Defined in gamepad.js:406

Called when gamepad axis value changed.

Event Payload:

  • event Object
    • gamepad Object

      The gamepad object

    • axis String

      Axis name

    • value Number

      New axis value

button-down

Defined in gamepad.js:386

Called when a gamepad button is pressed down.

Event Payload:

  • event Object
    • gamepad Object

      The gamepad object

    • control String

      Control name

button-up

Defined in gamepad.js:396

Called when a gamepad button is released.

Event Payload:

  • event Object
    • gamepad Object

      The gamepad object

    • control String

      Control name

connected

Defined in gamepad.js:353

Triggered when a new controller connects.

Event Payload:

  • device Object

disconnected

Defined in gamepad.js:370

Triggered when a controller disconnects.

Event Payload:

  • device Object

tick

Defined in gamepad.js:378

Called regularly with the latest controllers info.

Event Payload:

  • gamepads Array

unsupported

deprecated

Defined in gamepad.js:361

Deprecated: not used anymore. Any controller is supported.

Called when an unsupported controller connects.

Event Payload:

  • device Object