Creates a new GamepadEmulator object and monkey patches the browser getGamepads() API and gamepad events to report emulated gamepads
the threshold above which a variable button is considered a "pressed" button
add event listeners to the html/svg button elements of an onscreen gamepad to emulate gamepad input when touched, clicked or dragged
the index of the emulated gamepad to register events for
an array of config objects that set how each of the buttons on the onscreen gamepad should behave, and how they map to the emulated gamepad buttons.
add event listeners to the html/svg joystick elements of an onscreen gamepad to emulate gamepad input when dragged with a mouse, touch or pen.
the index of the emulated gamepad to register events for
an array of config objects that set how each of the joysticks on the onscreen gamepad should behave, and how they map to the emulated gamepad axes.
Protected
buttonthe threshold above which a variable button is considered a "pressed" button
removes event listeners added with AddButtonTouchEventListeners()
the index of the emulated gamepad to un-register events for
removes event listeners added with AddJoystickTouchEventListeners()
the index of the emulated gamepad to un-register events for
Protected
emulatedA list of all the emulated gamepads, where the index is the "gamepadIndex" passed when AddEmulatedGamepad() was called (Ie: there may be holes in the list), when an emulated gamepad is "connected" ie: call AddEmulatedGamepad(), it is added to this list at the provided index (or returns false if there is already an emulated gamepad at that index). when an emulated gamepad is "disconnected" ie: call removeEmulatedGamepad(), it is removed from this list provided index (or returns false if there is already an emulated gamepad at that index).
Protected
emulatedA list that mirrors the structure of GamepadEmulator.emulatedGamepads, but contains data internal to this class for keeping track of their state
Optional
getstores a reference to the real, unpatched navigator.getGamepads() function (if available) *
Protected
patchedthe reverse mapping array of GamepadEmulator.realGpadToPatchedIndexMap
Protected
realA list of the indecies of all the real gamepads that have ever been conected durring this browser session, where the array index is the "gamepadIndex" returned by the native gamepad api, and the value is the index that gamepad should be exposed at in the emulated getGamepads() array
Protected
undostores the function returned by monkeyPatchGamepadEvents() to undo the gamepad event monkey patch *
Protected
Static
instancea static class variable to tell if any other instances of the GamepadEmulator class are active, and throw an error if a new one is created
add event listeners to the html/svg button elements of an onscreen gamepad to emulate gamepad input when touched, clicked or dragged
the index of the emulated gamepad to register events for
an array of config objects that set how each of the buttons on the onscreen gamepad should behave, and how they map to the emulated gamepad buttons.
Protected
Addcreates a new emmulated gamepad at the given index as would be read in navigator.getGamepads
the index of the gamepad to create, pass null to create a new gamepad at the next available index
if a real gamepad is connected at the same index as this emulated one and overlayMode is true, the emulated gamepad values will get merged or overlayed on the real gamepad button and axis values, otherwise the emulated gamepad will be shifted to the next available index (appear as a separate gamepad from the real gamepad)
normally 18, the number of buttons on the gamepad
normally 4, the number of axes on the gamepad
add event listeners to the html/svg joystick elements of an onscreen gamepad to emulate gamepad input when dragged with a mouse, touch or pen.
the index of the emulated gamepad to register events for
an array of config objects that set how each of the joysticks on the onscreen gamepad should behave, and how they map to the emulated gamepad axes.
Protected
cloneProtected
monkeyProtected
monkeyoverwrite the browser gamepad api getGamepads() to return the emulated gamepad data for gamepad indexes corresponding to emulated gamepads if a real gamepad is found with the same index value as an emulated gamepad, the the navigator.getGamepads() list will either shift the emulated gamepad's index up to make room for the real gamepad when (emulatedGamepad.overlayMode = false), or it will return the emulated gamepad "overlayed" on the real one where buttons pressed or axes moved on both the real gamepad and the emulated one will show up on that gamepad.
emulates moving an axis on the gamepad at the given axis index
the index of the emulated gamepad to move the axis on
the index of the axis to move
the value to set the axis to between -1 and 1 (0 = center, -1 = left/up, 1 = right/down)
Protected
nextSearches for the next available index a new emulated gamepad could go and returns that index this means no emulated gamepad is at that index and either the no real gamepad is at that index, or a real gamepad is at that index, but the
is true.
Protected
nextSearches for the next available index a freshly connected real gamepad could go and returns that index this means no real gamepad is mapped to that index and either no emulated gamepad is at that index, or the emulated gamepad is in overlay mode
the index to start searching from
emulates pressing a button on an emulated gamepad at the given gamepad button index
the index of the emulated gamepad (as returned by navigator.getGamepads()) to press the button on
the index of the button to press on the gamepad - pass an array of indexes to control multiple buttons at once
the value to set the button to between 0 and 1 (0 = not pressed, 1 = fully pressed, 0.5 = half pressed) if this value is greater than the pressedThreshold from the constructor, the button will be considered pressed
Optional
touched: booleanwhether the button is considered "touched" or not, a "pressed" button is always considered "touched"
Class to handle emulated gamepads and injecting them into the browser getGamepads() and event listener APIs.