melonJS
    Preparing search index...

    Function vibrateGamepad

    • Vibrate a gamepad.

      Safe to call blind: with no pad in that slot, no motors, or a browser without the Gamepad API at all, it resolves false and does nothing. That is the whole error path, so game code never has to branch on support.

      Magnitudes default to FULL, unlike the underlying web API where every parameter defaults to zero and a bare playEffect("dual-rumble") is a silent no-op. vibrateGamepad(0) vibrates.

      A second call preempts the first on the same pad, which is what makes a rapid series of hits read as a rapid series of hits rather than a queue. That is for DISTINCT events: a sustained rumble should be one effect with a long duration, not a call per frame, which would spend a promise and a preempted effect every frame to produce one continuous one.

      Parameters

      Returns Promise<boolean>

      whether the effect ran to completion. false covers unsupported, preempted by a later call, and rejected by the device alike — a rumble is feedback, and nothing sensible branches on which of those happened.

      // a short, sharp knock
      input.vibrateGamepad(0, { duration: 90, strongMagnitude: 0.4, weakMagnitude: 0.8 });
      // and a long heavy one for something big
      input.vibrateGamepad(0, { duration: 600, strongMagnitude: 1, weakMagnitude: 0.5 });