mwg API
    Preparing search index...

    Class PlayerInput

    A player-scoped view over mwg/core's Input module for same-screen local multiplayer.

    Input has no concept of a player: Action is a bare string, and its bindings/held/ onAction all live at module scope. Binding the same action name to two pads directly - Input.bindButton('confirm', 0, [0]) and Input.bindButton('confirm', 1, [0]) - does not give two independent "confirm"s; both bindings land in the very same action's key set, so either pad pressing it fires the one shared onAction, with no way to tell which pad did.

    This does not change Input itself - it is a thin, purely additive naming convention: every action a PlayerInput binds or queries is transparently prefixed with this player's own id, so two players' "confirm" become two distinct actions ("p1:confirm", "p2:confirm") that never collide. A single-player game using Input's bare action names directly is entirely unaffected.

    import { PlayerInput } from '@datamoc/mw_games/core';

    const player1 = new PlayerInput('p1', { padIndex: 0 });
    const player2 = new PlayerInput('p2', { padIndex: 1 });

    player1.bind('confirm', ['Enter']);
    player2.bind('confirm', ['Space']);

    // each player's "confirm" fires independently, even though both call it "confirm"
    if (player1.justPressed('confirm')) console.log('player 1 confirmed');
    Index
    id: string
    padIndex?: number
    • binds this player's own action to keyboard keys, independent of any other player's binding for the same action name

      Parameters

      • action: string
      • keys: readonly string[]

      Returns void

    • binds this player's own action to an axis direction on their own padIndex

      Parameters

      • action: string
      • axis: number
      • direction: -1 | 1

      Returns void

    • binds this player's own action to a button on their own padIndex

      Parameters

      • action: string
      • buttons: readonly number[]

      Returns void

    • binds this player's own action to an on-screen touch control, independent of any other player's binding for the same action name

      Parameters

      • action: string
      • id: string = action

      Returns void

    • every key/pad binding for this player's own action, in the same shape Input.exportBindings uses

      Parameters

      • action: string

      Returns string[]

    • presses this player's own touch control, bound previously with bindTouch

      Parameters

      • id: string

      Returns void