melonJS
    Preparing search index...

    Class GamepadPlugin

    On-screen touch controls, reported as a gamepad: sticks and buttons drawn over the game, read by the engine as a pad in a gamepad slot. Everything a game binds with input.bindGamepad answers to them, so the same code reads a real pad and the touch controls.

    Register it once the application is created:

    plugin.register(GamepadPlugin, "gamepad", { buttons: 2 });
    

    The controls follow each finger on its own, so a stick can be held while a button is pressed; a touch that starts on a control does not reach the game. They are drawn over the whole frame, above every renderable and every camera, and outlive stage changes.

    Hierarchy

    • BasePlugin
      • GamepadPlugin
    Index
    app: Application

    a reference to the app/game that registered this plugin

    buttons: readonly VirtualButton[]

    the buttons, in the order of the options

    index: number

    the gamepad slot the controls report in

    sticks: readonly VirtualStick[]

    the sticks, in the order of the options

    version: string

    define the minimum required version of melonJS this can be overridden by the plugin

    • get enabled(): boolean

      Whether the controls are switched on. Set it to show or hide them at any time, as on a stage that only needs a tap. Switched off, they let go of everything they held.

      The controls can be switched on and still hidden, while the player uses a real pad: GamepadPlugin#visible says whether they show.

      Returns boolean

    • set enabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get visible(): boolean

      Whether the controls are on the screen: switched on, and not hidden for a real pad. A game can read it to word its prompts ("tap" rather than a key).

      Returns boolean