ecspresso
    Preparing search index...

    Function createInputPlugin

    • Create an input plugin for ECSpresso.

      Provides:

      • Frame-accurate keyboard state (isDown, justPressed, justReleased)
      • Pointer position/delta and button state (mouse + touch via PointerEvent)
      • Up to 4 gamepads polled per frame, with radial deadzone on sticks and analog button values
      • Unified action mapping (keyboard + pointer + any pad)
      • Per-player action maps for local co-op (definePlayer, player(id))
      • Automatic listener cleanup on detach

      Type Parameters

      • A extends string = string
      • G extends string = "input"

      Parameters

      Returns Plugin<
          WithResources<EmptyConfig, InputResourceTypes<A>>,
          EmptyConfig,
          "input-state",
          G,
          never,
          never,
      >

      const ecs = ECSpresso.create()
      .withPlugin(createInputPlugin({
      actions: {
      jump: { keys: [' ', 'ArrowUp'], gamepadButtons: [{ pad: 0, button: 0 }] },
      shoot: { keys: ['z'], pointerButtons: [0] },
      },
      players: {
      p1: { jump: { keys: [' '] }, shoot: { keys: ['z'] } },
      p2: {
      jump: { gamepadButtons: gamepadButtonsOn(0, 0) },
      shoot: { gamepadButtons: gamepadButtonsOn(0, 2) },
      },
      },
      }))
      .build();

      const input = ecs.getResource('inputState');
      if (input.actions.justActivated('jump')) { ... } // any source
      if (input.player('p1')?.actions.isActive('jump')) { ... } // just player 1
      if (input.gamepads[0].isDown(0)) { ... } // raw pad 0 A-button