Class Gamepads

The Gamepads class provides an easy way for keeping shimi Gamepad objects synced up to Gamepad objects from the Gamepad Web API.

When a gamepad gets added to a Gamepads instance, it is added as unmatched. With each update cycle, Gamepads will attempt to pair up any unmatched gamepad objects with incoming gamepad data. Once a match is established, the gamepad object will get updated with new gamepad data each cycle, allowing for the state of each button to be easily tracked.

Hierarchy

  • Gamepads

Implements

Constructors

  • Parameters

    • updateProvider: (() => Gamepad[])

      This is a function that will be called with each update to get new Gamepad data.

      Typically this should be something like: new Gamepads(() => navigator.getGamepads());

        • (): Gamepad[]
        • Returns Gamepad[]

    Returns Gamepads

Accessors

  • get activeGamepads(): IGamepad[]
  • The collection of shimi gamepads which have been matched up to incoming gamepad data.

    Returns IGamepad[]

  • get isFinished(): boolean
  • Returns true if the finish() method has been called.

    Returns boolean

  • get ref(): string
  • Provides a way of identifying keyboards so they can be easily retrieved later

    Returns string

  • set ref(value: string): void
  • Parameters

    • value: string

    Returns void

  • get typeName(): string
  • Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable.

    Returns string

Methods

  • This method adds a new shimi Gamepad object to the collection of unmatched gamepads.

    Parameters

    • gamepad: IGamepad

      The gamepad to be added.

    Returns void

  • Calling this tells the Gamepads object to stop whatever it's doing and that it will no longer be used.

    Returns void

  • This method is intended to be called by a clock to provide regular updates. It should not be called by consumers of the library.

    The method first of all attempts to match up any unmatched gamepad objects with incoming gamepad data. It then loops through each matched gamepad and updates the object's data with what's coming from the matched up gamepad data.

    Parameters

    • deltaMs: number

      How many milliseconds have passed since the last update cycle.

    Returns void

  • Provides a way for setting the ref through a chained function call. For example:

    clock.addChild(new Gamepads(() => navigator.getGamepads()).withRef('gamepads'));
    

    Returns

    The calling object.

    Parameters

    • ref: string

      The ref to set on the object.

    Returns IClockChild

Generated using TypeDoc