Skip to content

Commit

Permalink
Added gamepad vibration support for browsers (#1019)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefvel authored Apr 28, 2022
1 parent b5530d5 commit d1d0008
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions hxd/Pad.hx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,24 @@ class Pad {
d.rumble( strength, Std.int(time_s*1000.) );
#elseif (hldx || usesys)
d.rumble( strength, time_s );
#elseif js
var d: Dynamic = d;
var time = Std.int(time_s * 1000.);

// FF and Safari
if (d.hapticActuators != null && d.hapticActuators.length > 0) {
d.hapticActuators[0].pulse(strength, time);
return;
}

// Chrome
if (d.vibrationActuator != null) {
d.vibrationActuator.playEffect('dual-rumble', {
duration: time,
strongMagnitude: strength,
weakMagnitude: strength,
});
}
#end
}

Expand Down

0 comments on commit d1d0008

Please sign in to comment.