Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Gamepad

Gamepad holds state information for a connected controller. See Gamepads for more information on handling controller input.

Hierarchy

Implements

Index

Constructors

constructor

Properties

Private _axes

_axes: number[] = new Array(4)

Private _buttons

_buttons: number[] = new Array(16)

connected

connected: boolean = false

eventDispatcher

eventDispatcher: EventDispatcher

Direct access to the game object event dispatcher.

navigatorGamepad

navigatorGamepad: INavigatorGamepad

Methods

emit

  • emit(eventName: string, eventObject?: GameEvent): void
  • Emits a new event

    Parameters

    • eventName: string

      Name of the event to emit

    • Optional eventObject: GameEvent

      Data associated with this event

    Returns void

getAxes

  • getAxes(axes: Axes): number
  • Gets the given axis value between -1 and 1. Values below MinAxisMoveThreshold are considered 0.

    Parameters

    Returns number

getButton

  • getButton(button: Buttons): number
  • Gets the given button value between 0 and 1

    Parameters

    Returns number

isButtonPressed

  • isButtonPressed(button: Buttons, threshold?: number): boolean
  • Whether or not the given button is pressed

    Parameters

    • button: Buttons

      The button to query

    • Default value threshold: number = 1

      The threshold over which the button is considered to be pressed

    Returns boolean

off

  • off(eventName: string, handler?: function): void
  • Alias for removeEventListener. If only the eventName is specified it will remove all handlers registered for that specific event. If the eventName and the handler instance are specified only that handler will be removed.

    Parameters

    • eventName: string

      Name of the event to listen for

    • Optional handler: function

      Event handler for the thrown event

    Returns void

on

  • on(eventName: string, handler: function): void
  • Alias for addEventListener. You can listen for a variety of events off of the engine; see the events section below for a complete list.

    Parameters

    • eventName: string

      Name of the event to listen for

    • handler: function

      Event handler for the thrown event

    Returns void

updateAxes

  • updateAxes(axesIndex: number, value: number): void
  • Parameters

    • axesIndex: number
    • value: number

    Returns void

updateButton

  • updateButton(buttonIndex: number, value: number): void
  • Parameters

    • buttonIndex: number
    • value: number

    Returns void

Static extend

  • extend(methods: any): any
  • You may wish to extend native Excalibur functionality in vanilla Javascript. Any method on a class inheriting Class may be extended to support additional functionality. In the example below we create a new type called MyActor.

    var MyActor = Actor.extend({
    
       constructor: function() {
          this.newprop = 'something';
          Actor.apply(this, arguments);
       },
    
       update: function(engine, delta) {
          // Implement custom update
          // Call super constructor update
          Actor.prototype.update.call(this, engine, delta);
    
          console.log("Something cool!");
       }
    });
    
    var myActor = new MyActor(100, 100, 100, 100, Color.Azure);
    

    In TypeScript, you only need to use the extends syntax, you do not need to use this method of extension.

    Parameters

    • methods: any

      A JSON object contain any methods/properties you want to extend

    Returns any