phaser - v4.0.0-rc.4
    Preparing search index...

    The Gamepad Plugin is an input plugin that belongs to the Scene-owned Input system.

    Its role is to listen for native DOM Gamepad Events and then process them.

    You do not need to create this class directly, the Input system will create an instance of it automatically.

    You can access it from within a Scene using this.input.gamepad.

    To listen for a gamepad being connected:

    this.input.gamepad.once('connected', function (pad) {
    // 'pad' is a reference to the gamepad that was just connected
    });

    Note that the browser may require you to press a button on a gamepad before it will allow you to access it, this is for security reasons. However, it may also trust the page already, in which case you won't get the 'connected' event and instead should check GamepadPlugin.total to see if it thinks there are any gamepads already connected.

    Once you have received the connected event, or polled the gamepads and found them enabled, you can access them via the built-in properties GamepadPlugin.pad1 to pad4, for up to 4 game pads. With a reference to the gamepads you can poll its buttons and axis sticks. See the properties and methods available on the Gamepad class for more details.

    As of September 2020 Chrome, and likely other browsers, will soon start to require that games requesting access to the Gamepad API are running under SSL. They will actively block API access if they are not.

    For more information about Gamepad support in browsers see the following resources:

    https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API https://www.smashingmagazine.com/2015/11/gamepad-api-in-web-games/ http://html5gamepad.com/

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    enabled: boolean

    A boolean that controls if the Gamepad Manager is enabled or not. Can be toggled on the fly.

    gamepads: Input.Gamepad.Gamepad[]

    An array of the connected Gamepads.

    A reference to the first connected Gamepad.

    This will be undefined if either no pads are connected, or the browser has not yet issued a gamepadconnect, which can happen even if a Gamepad is plugged in, but hasn't yet had any buttons pressed on it.

    A reference to the second connected Gamepad.

    This will be undefined if either no pads are connected, or the browser has not yet issued a gamepadconnect, which can happen even if a Gamepad is plugged in, but hasn't yet had any buttons pressed on it.

    A reference to the third connected Gamepad.

    This will be undefined if either no pads are connected, or the browser has not yet issued a gamepadconnect, which can happen even if a Gamepad is plugged in, but hasn't yet had any buttons pressed on it.

    A reference to the fourth connected Gamepad.

    This will be undefined if either no pads are connected, or the browser has not yet issued a gamepadconnect, which can happen even if a Gamepad is plugged in, but hasn't yet had any buttons pressed on it.

    scene: Scene

    A reference to the Scene that this Input Plugin is responsible for.

    sceneInputPlugin: InputPlugin

    A reference to the Scene Input Plugin that created this Keyboard Plugin.

    settings: SettingsObject

    A reference to the Scene Systems Settings.

    target: any

    The Gamepad Event target, as defined in the Game Config. Typically the browser window, but can be any interactive DOM element.

    total: number

    The total number of connected game pads.

    Methods

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Calls each of the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • ...args: any[]

        Additional arguments that will be passed to the event handler.

      Returns boolean

    • Checks to see if both this plugin and the Scene to which it belongs is active.

      Returns boolean

    • Return the number of listeners listening to a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns number

    • Return the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns Function[]

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Add a one-time listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this