Reference Source
public class | source

GamepadManagerSingleton

You can directly use an instance of this class. GamepadManager

A gamepadmanager to help with games / handling input from a controller

TODO:

  • Currently bluetooth gamepads when disconnecting (PS4 only) do no fire a disconnected event. Manually calling `this.gamepad.vibrationActuator.reset()` can force it to call a disconnect event, but this is a messy way of checking each tick to see if the gamepad is still connected. It also will cancel ongoing vibrations. Find a fix. (This is a GamepadAPI issue/OS issue/not code wise issue)

Static Method Summary

Static Public Methods
public static

getAngle(pStartPoint: Object, pEndPoint: Object): number

Gets the angle between two points

Constructor Summary

Public Constructor
public

Creates the instance and assigns event handlers to gamepad events

Member Summary

Public Members
public

Object containing the callback for when a controller is connected

public

connectedControllers: Set<Controller> | null

Controllers connected before an event listener caught them.

public

Object containing all connected controllers

public

Object containing the callback for when a controller is disconnected

public

unassignedControllers: Set<Controller> | null

Controllers connected before an event listener caught them.

public

version: *

The version of the module.

Private Members
private

The logger module this module uses to log errors / logs.

Method Summary

Public Methods
public
public

getMainController(): Gamepad

This gets the first controller connected.

public

handleGamepadConnected(pGamepadEvent: pGamepadEvent)

Listener function for when a gamepad is connected

public

handleGamepadDisconnected(pGamepadEvent: pGamepadEvent)

Listener function for when the gamepad is disconnected

public

on(pEvent: Object, pCallback: Function): GamepadManagerSingleton

Attaches a callback to the specified event.

public

Get the latest game state of the connected gamepads (Chrome only saves snapshots of the state, we have to keep polling to get updated states)

Static Public Methods

public static getAngle(pStartPoint: Object, pEndPoint: Object): number source

Gets the angle between two points

Params:

NameTypeAttributeDescription
pStartPoint Object

The starting point

pEndPoint Object

The ending point

Return:

number

The angle between the starting point and the ending point

Public Constructors

public constructor() source

Creates the instance and assigns event handlers to gamepad events

Public Members

public connectHandler: Object source

Object containing the callback for when a controller is connected

public connectedControllers: Set<Controller> | null source

Controllers connected before an event listener caught them.

public controllers: Object source

Object containing all connected controllers

public disconnectHandler: Object source

Object containing the callback for when a controller is disconnected

public unassignedControllers: Set<Controller> | null source

Controllers connected before an event listener caught them.

public version: * source

The version of the module.

Private Members

private logger: Object source

The logger module this module uses to log errors / logs.

Public Methods

public getControllers(): Array source

Return:

Array

An array of all connected controllers

public getMainController(): Gamepad source

This gets the first controller connected. This controller is dominant

Return:

Gamepad

The first controller connected

public handleGamepadConnected(pGamepadEvent: pGamepadEvent) source

Listener function for when a gamepad is connected

Params:

NameTypeAttributeDescription
pGamepadEvent pGamepadEvent

A gamepad event

public handleGamepadDisconnected(pGamepadEvent: pGamepadEvent) source

Listener function for when the gamepad is disconnected

Params:

NameTypeAttributeDescription
pGamepadEvent pGamepadEvent

A gamepad event

public on(pEvent: Object, pCallback: Function): GamepadManagerSingleton source

Attaches a callback to the specified event.

Params:

NameTypeAttributeDescription
pEvent Object

The event to attach the callback to

pCallback Function

The function to be called when the event is triggered

Return:

GamepadManagerSingleton

The GamepadManagerSingleton instance

public pollGamepadState() source

Get the latest game state of the connected gamepads (Chrome only saves snapshots of the state, we have to keep polling to get updated states)