like2d
    Preparing search index...

    Interface Input

    Used to map inputs (from keyboard, mouse, or gamepad) into actions.

    setAction allows for set-and-forget mappings. Good for one-off games.

    Example:

    // bind action jump
    like.load() {
    like.input.setAction('jump', ['KeyX', 'Space', 'ButtonBottom'])
    }

    like.actionpressed(action) {
    if (action == 'jump') {
    player.tryJumping();
    }
    }

    For more sophisticated games, see also:

    These allow for programmatic binding based on events. For example:

    let currentlyMapping = 'jump';

    // Watch for gamepad and keyboard events
    like.keypressed = (code) => {
    if (currentlyMapping) {
    like.input.appendToAction(currentlyMapping, code);
    }
    }
    like.gamepadpressed = (name) => {
    if (currentlyMapping) {
    like.input.appendToAction(currentlyMapping, name);
    }
    }

    // Print some info about the current mapping
    like.draw = () => {
    if (currentlyMapping) {
    myGame.statusLine =
    `Mapped ${like.input.getActionMapping(currentlyMapping)} to ${currentlyMapping}`
    }
    }
    interface Input {
        appendToAction(action: string, input: string | InputBinding): void;
        getActionMapping(action: string): InputBinding[];
        isDown(action: string): boolean;
        justPressed(action: string): boolean;
        justReleased(action: string): boolean;
        setAction(action: string, inputs: (string | InputBinding)[]): void;
    }
    Index

    Methods

    • Parameters

      • action: string

      Returns boolean

    • Parameters

      • action: string

      Returns boolean

    • Parameters

      • action: string

      Returns boolean

    • This is the easiest way to set-and-forget input => action mapping.

      Or, it's a helper to remove actions -- setAction(action, []) will simply clear the action away.

      For input strings:

      • Mouse is MouseLeft, MouseRight, or MouseMiddle.
      • Joypad is 'Left', 'L1', or any joypad button. LikeButton
      • Keyboard is the name of scancodes, which are based on key positions. Choose from a subset of portable, web-safe scancodes:
        • Alphabetical: KeyA, KeyB, ...
        • Numeric: Digit0, Digit1, ...
        • ArrowLeft, ArrowRight, ArrowUp, ArrowDown
        • ShiftLeft, ShiftRight
        • Space
        • Minus
        • Equal (also has a plus sign)
        • BracketLeft and BracketRight
        • Semicolon
        • Quote
        • Backquote (also has tilde)
        • Backslash
        • Comma
        • Period
        • Slash
        • Backspace
        • Enter

      Parameters

      Returns void