Engine API Reference - v2.6.1
    Preparing search index...

    Class GamePad

    A GamePad stores information about a gamepad from the Gamepad API.

    Index

    Properties

    hand: string

    The hand this gamepad is usually handled on. Only relevant for XR pads. Value is either "left", "right" or "none".

    id: string

    The identifier for the gamepad. Its structure depends on device.

    index: number

    The index for this controller. A gamepad that is disconnected and reconnected will retain the same index.

    map: any

    The buttons and axes map.

    mapping: string

    The gamepad mapping detected by the browser. Value is either "standard", "xr-standard", "" or "custom". When empty string, you may need to update the mapping yourself. "custom" means you updated the mapping.

    Accessors

    • get axes(): number[]

      Gets the values from analog axes present on the GamePad. Values are between -1 and 1.

      Returns number[]

    Methods

    • Get the value of one of the analog axes of the pad.

      Parameters

      • axis: number

        The axis to get the value of, use constants PAD_L_STICK_X, etc.

      Returns number

      The value of the axis between -1 and 1.

    • Returns the value of a button between 0 and 1, with 0 representing a button that is not pressed, and 1 representing a button that is fully pressed.

      Parameters

      • button: number

        The button to retrieve, use constants PAD_FACE_1, etc.

      Returns number

      The value of the button between 0 and 1.

    • Returns true if the button is pressed.

      Parameters

      • button: number

        The button to test, use constants PAD_FACE_1, etc.

      Returns boolean

      True if the button is pressed.

    • Returns true if the button is touched.

      Parameters

      • button: number

        The button to test, use constants PAD_FACE_1, etc.

      Returns boolean

      True if the button is touched.

    • Make the gamepad vibrate.

      Parameters

      • intensity: number

        Intensity for the vibration in the range 0 to 1.

      • duration: number

        Duration for the vibration in milliseconds.

      • Optionaloptions: { startDelay?: number; strongMagnitude?: number; weakMagnitude?: number }

        Options for special vibration pattern.

        • OptionalstartDelay?: number

          Delay before the pattern starts, in milliseconds. Defaults to 0.

        • OptionalstrongMagnitude?: number

          Intensity for strong actuators in the range 0 to 1. Defaults to intensity.

        • OptionalweakMagnitude?: number

          Intensity for weak actuators in the range 0 to 1. Defaults to intensity.

      Returns Promise<boolean>

      Return a Promise resulting in true if the pulse was successfully completed.

    • Update the map for this gamepad.

      Parameters

      • map: {
            axes: string[];
            buttons: string[];
            mapping?: "custom";
            synthesizedButtons?: any;
        }

        The new mapping for this gamepad.

        • axes: string[]

          Axes mapping for this gamepad.

        • buttons: string[]

          Buttons mapping for this gamepad.

        • Optionalmapping?: "custom"

          New mapping format. Will be forced into "custom".

        • OptionalsynthesizedButtons?: any

          Information about buttons to pull from axes for this gamepad. Requires definition of axis index, min value and max value.

      Returns void

      this.pad.updateMap({
      buttons: [[
      'PAD_FACE_1',
      'PAD_FACE_2',
      'PAD_FACE_3',
      'PAD_FACE_4',
      'PAD_L_SHOULDER_1',
      'PAD_R_SHOULDER_1',
      'PAD_L_SHOULDER_2',
      'PAD_R_SHOULDER_2',
      'PAD_SELECT',
      'PAD_START',
      'PAD_L_STICK_BUTTON',
      'PAD_R_STICK_BUTTON',
      'PAD_VENDOR'
      ],
      axes: [
      'PAD_L_STICK_X',
      'PAD_L_STICK_Y',
      'PAD_R_STICK_X',
      'PAD_R_STICK_Y'
      ],
      synthesizedButtons: {
      PAD_UP: { axis: 0, min: 0, max: 1 },
      PAD_DOWN: { axis: 0, min: -1, max: 0 },
      PAD_LEFT: { axis: 0, min: -1, max: 0 },
      PAD_RIGHT: { axis: 0, min: 0, max: 1 }
      }
      });
    • Return true if the button was pressed since the last update.

      Parameters

      • button: number

        The button to test, use constants PAD_FACE_1, etc.

      Returns boolean

      Return true if the button was pressed, false if not.

    • Return true if the button was released since the last update.

      Parameters

      • button: number

        The button to test, use constants PAD_FACE_1, etc.

      Returns boolean

      Return true if the button was released, false if not.

    • Return true if the button was touched since the last update.

      Parameters

      • button: number

        The button to test, use constants PAD_FACE_1, etc.

      Returns boolean

      Return true if the button was touched, false if not.