Skip to main content

Gamepads

Excalibur leverages the HTML5 Gamepad API where it is supported to provide controller support for your games.

Index

Constructors

constructor

Properties

publicenabled

enabled: boolean = false

Whether or not to poll for Gamepad input (default: false)

publicevents

events: EventEmitter<GamepadEvents> = ...

publicsupported

supported: boolean = !!(<any>navigator).getGamepads

Whether or not Gamepad API is supported

publicstaticMinAxisMoveThreshold

MinAxisMoveThreshold: number = 0.05

The minimum value an axis has to move before considering it a change

Methods

publicat

  • Safely retrieves a Gamepad at a specific index and creates one if it doesn't yet exist


    Parameters

    • index: number

    Returns Gamepad

publiccount

  • count(): number
  • Gets the number of connected gamepads


    Returns number

publicemit

  • emit<TEventName>(eventName: TEventName, event: GamepadEvents[TEventName]): void
  • emit(eventName: string, event?: any): void
  • Type parameters

    Parameters

    • eventName: TEventName
    • event: GamepadEvents[TEventName]

    Returns void

publicgetValidGamepads

  • Returns a list of all valid gamepads that meet the minimum configuration requirement.


    Returns Gamepad[]

publicinit

  • init(): void
  • Returns void

publicoff

  • off<TEventName>(eventName: TEventName, handler: Handler<GamepadEvents[TEventName]>): void
  • off(eventName: string, handler: Handler<unknown>): void
  • off(eventName: string): void
  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<GamepadEvents[TEventName]>

    Returns void

publicon

  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<GamepadEvents[TEventName]>

    Returns Subscription

publiconce

  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<GamepadEvents[TEventName]>

    Returns Subscription

publicsetMinimumGamepadConfiguration

  • setMinimumGamepadConfiguration(config: GamepadConfiguration): void
  • Sets the minimum gamepad configuration, for example {axis: 4, buttons: 4} means this game requires at minimum 4 axis inputs and 4 buttons, this is not restrictive all other controllers with more axis or buttons are valid as well. If no minimum configuration is set all pads are valid.


    Parameters

    • config: GamepadConfiguration

    Returns void

publictoggleEnabled

  • toggleEnabled(enabled: boolean): void
  • Parameters

    • enabled: boolean

    Returns void

publicupdate

  • update(): void
  • Updates Gamepad state and publishes Gamepad events


    Returns void