melonJS
    Preparing search index...

    Function bindGamepad

    • Associate a gamepad event to a keycode

      Parameters

      • index: number

        Gamepad index

      • button: { code: number; threshold?: number; type: "buttons" | "axes" }

        Button/Axis definition

        • code: number

          button or axis code id

        • Optionalthreshold?: number

          how far past the deadzone the axis must travel to trigger the keycode. It is ADDED to input.setGamepadDeadzone, it does not replace it, so with the default deadzone of 0.1 a threshold of 0.5 fires at 0.6 of full deflection. Its SIGN picks the half of the axis to watch: negative for left/up, positive for right/down, and the two halves are bound separately. Ignored for "buttons", which take the browser's own pressed state; the deadzone reaches a button only where a non-standard mapping routes an axis onto one through its analog array.

        • type: "buttons" | "axes"

          "buttons" or "axes"

      • keyCode: number

        (See input.KEY)

      Returns void

      if keyCode has no action bound to it yet — call input.bindKey first.

      // enable the keyboard
      me.input.bindKey(me.input.KEY.X, "shoot");
      ...
      // map the lower face button on the first gamepad to the X key
      me.input.bindGamepad(0, {type:"buttons", code: me.input.GAMEPAD.BUTTONS.FACE_1}, me.input.KEY.X);
      // map the left half of the stick to LEFT, firing at 0.6 of full travel
      // (0.1 deadzone + 0.5 threshold), and the right half to RIGHT
      me.input.bindGamepad(0, {type:"axes", code: me.input.GAMEPAD.AXES.LX, threshold: -0.5}, me.input.KEY.LEFT);
      me.input.bindGamepad(0, {type:"axes", code: me.input.GAMEPAD.AXES.LX, threshold: 0.5}, me.input.KEY.RIGHT);