like2d
    Preparing search index...

    Interface Gamepad

    LIKE Gamepad Wrapper

    • Allows events/callbacks to be sent from joy buttons.
    • Can track if any gamepad has a button pressed / just pressed.
    • Remaps raw input numbers to readable strings -- by default using SDL database.

    If you're planning on supporting gamepads, please include a way to generate GamepadMapping and set it with Gamepad.setMapping. Perhaps trigger it on gamepadconnected events.

    If you don't want to make your own, take a look at scene/prefab/mapGamepad

    For games with heavy and varied gamepad use, mapping buttons is essential.

    But if your game relies on a small set of logical actions like 'accept' or 'jump', don't hesitate to reach for input in order to map based on actions instead.

    interface Gamepad {
        enableAutoLoadMapping(enable: boolean): void;
        fullButtonName(name: LikeButton): string;
        getMapping(index: number): GamepadMapping | undefined;
        getSticks(target: number): Vector2[];
        isDown(
            target: GamepadTarget,
            button: number | LikeButton,
        ): boolean | undefined;
        justPressed(
            target: GamepadTarget,
            button: number | LikeButton,
        ): boolean | undefined;
        loadMapping(index: number): GamepadMapping | undefined;
        saveMapping(index: number, mapping: GamepadMapping): void;
        setMapping(index: number, mapping: GamepadMapping, save?: boolean): void;
    }
    Index

    Methods

    • Enable automatically loading mappings.

      When a gamepad with a known (to this system) ID is plugged in, this will load the previously saved mapping.

      Parameters

      • enable: boolean

      Returns void

    • Get a controller mapping. Note that modifying this mapping in place will modify the target controller. However, use setMapping to finalize the mapping.

      Parameters

      • index: number

      Returns GamepadMapping | undefined

    • Parameters

      • target: number

        Which controller?

      Returns Vector2[]

      all of the sticks. Convention is 0 = left, 1 = right.

    • Set the mapping for a particular controller.

      Set save = false if you don't want this written into localstorage.

      Parameters

      Returns void