Gamepad Class
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]
Parameters:
-
[updateStrategy]
Object optionalan update strategy, defaulting to AnimFrameUpdateStrategy
Item Index
Methods
Properties
Events
- axis-changed
- button-down
- button-up
- connected
- disconnected
- tick
- unsupported deprecated
Methods
_addAxisUpdater
-
gamepad
-
mapping
-
index
Adds an updater for an axis control
Parameters:
-
gamepad
Objectthe gamepad for which to create the updater
-
mapping
Objectthe mapping on which to work on
-
index
Numberaxis index
_addButtonUpdater
-
gamepad
-
mapping
-
index
Adds an updater for a button control
Parameters:
-
gamepad
Objectthe gamepad for which to create the updater
-
mapping
Objectthe mapping on which to work on
-
index
Numberbutton index
_applyDeadzoneMaximize
-
value
-
[deadzone]
-
[maximizeThreshold]
Applies deadzone and maximization.
You can change the thresholds via deadzone and maximizeThreshold members.
Parameters:
-
value
NumberValue to modify
-
[deadzone]
Number optionalDeadzone to apply
-
[maximizeThreshold]
Number optionalFrom which value to maximize value
_connect
-
gamepad
Registers given gamepad.
Parameters:
-
gamepad
ObjectGamepad to connect to
_createAxisGetter
-
gamepad
-
axes
-
index
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
Objectthe gamepad for which to create a getter
-
axes
Objectthe mappings entry for the axes
-
index
Numberthe specific axis entry
Returns:
a getter returning the value for the requested axis
_createButtonGetter
-
gamepad
-
buttons
-
index
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
Objectthe gamepad for which to create a getter
-
buttons
Objectthe mappings entry for the buttons
-
index
Numberthe specific button entry
Returns:
a getter returning the value for the requested button
_disconnect
-
gamepad
Disconnects from given gamepad.
Parameters:
-
gamepad
ObjectGamepad to disconnect
_fire
-
event
-
data
Fires an internal event with given data.
Parameters:
-
event
StringEvent to fire, one of Gamepad.Event..
-
data
Data to pass to the listener
_fireAxisChangedEvent
-
gamepad
-
controlName
-
value
Fires an AXIS_CHANGED event
Parameters:
-
gamepad
Objectthe gamepad to notify for
-
controlName
Stringname of the control that changes its value
-
value
Numberthe new value
_resolveControllerType
-
id
Resolves controller type from its id.
Parameters:
-
id
StringController id
Returns:
Controller type, one of Gamepad.Type
_resolveMapping
-
gamepad
Parameters:
-
gamepad
Objectthe gamepad for which to resolve the mapping
Returns:
a mapping object for the given gamepad
_update
()
private
Updates the controllers, triggering TICK events.
bind
-
event
-
listener
Binds a listener to a gamepad event.
Parameters:
-
event
StringEvent to bind to, one of Gamepad.Event..
-
listener
FunctionListener to call when given event occurs
Returns:
Self
count
()
Number
Returns the number of connected gamepads.
Returns:
envMatchesFilter
-
filter
-
env
Parameters:
-
filter
Objectthe filter object describing properties to match
-
env
Objectthe environment object that is matched against filter
Returns:
true if env is covered by filter
getNullPlatform
()
Object
static
Returns:
a platform that does not support anything
init
()
Boolean
Initializes the gamepad.
You usually want to bind to the events first and then initialize it.
Returns:
true if a supporting platform was detected, false otherwise.
resolvePlatform
-
listener
Resolves platform.
Parameters:
-
listener
Objectthe listener to handle _connect() or _disconnect() calls
Returns:
A platform instance
unbind
-
[type]
-
[listener]
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 optionalType of listener to remove
-
[listener]
Function optionalThe listener function to remove
Returns:
Was unbinding the listener successful
Properties
Mappings
Unknown
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
List of factories of supported platforms. Currently available platforms: WebKitPlatform, FirefoxPlatform,
StandardAxes
Unknown
List of standard axis names. The index is the according standard axis index as per standard.
StandardButtons
Unknown
List of standard button names. The index is the according standard button index as per standard.
StandardMapping
Unknown
The standard mapping that represents the mapping as per definition. Each button and axis map to the same index.
Type
Unknown
List of supported controller types.
Sub-properties:
-
PLAYSTATION
StringPlaystation controller
-
LOGITECH
StringLogitech controller
-
XBOX
StringXBOX controller
-
UNKNOWN
StringUnknown controller
UpdateStrategies
Unknown
The available update strategies
Sub-properties:
-
AnimFrameUpdateStrategy
AnimFrameUpdateStrategy -
ManualUpdateStrategy
ManualUpdateStrategy
Events
axis-changed
Called when gamepad axis value changed.
Event Payload:
-
event
Object-
gamepad
ObjectThe gamepad object
-
axis
StringAxis name
-
value
NumberNew axis value
-
connected
Triggered when a new controller connects.
Event Payload:
-
device
Object
disconnected
Triggered when a controller disconnects.
Event Payload:
-
device
Object
tick
Called regularly with the latest controllers info.
Event Payload:
-
gamepads
Array
unsupported
deprecated
Called when an unsupported controller connects.
Event Payload:
-
device
Object