Skip to content

Commit

Permalink
Added Rumble On Button Press
Browse files Browse the repository at this point in the history
  • Loading branch information
YoRu-Cat committed Mar 10, 2024
1 parent 4368251 commit bf9a774
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,25 @@ function updateStick(elementId, leftRightAxis, upDownAxis) {
stick.setAttribute("cx", x + stickLeftRight);
stick.setAttribute("cy", y + stickUpDown);
}
function handleRumble(gamepad) {
const rumbleOnButtonPress = document.getElementById("rumble-on-button-press");
if (rumbleOnButtonPress.checked) {
if (gamepad.buttons.some((button) => button.value > 0)) {
gamepad.vibrationActuator.playEffect("dual-rumble", {
startDelay: 0,
duration: 25,
weakMagnitude: 1.0,
strongMagnitude: 1.0,
});
}
}
}
function gameLoop() {
if (controllerIndex !== null) {
const gamepad = navigator.getGamepads()[controllerIndex];
handleButtons(gamepad.buttons);
handleSticks(gamepad.axes);
handleRumble(gamepad);
}
requestAnimationFrame(gameLoop);
}
Expand Down

0 comments on commit bf9a774

Please sign in to comment.