Skip to content

Commit

Permalink
make sure black appears when a button is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mounir Lamouri committed Sep 23, 2024
1 parent d673d17 commit 8a393e5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions latency/gamepad-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</body>
<script>
let gamepad = null;
let isBlack = false;
let buttonsPressed = null;

window.addEventListener('gamepadconnected', (event) => {
Expand Down Expand Up @@ -44,6 +43,14 @@
return false;
}

function oneButtonPressed() {
for (let i = 0; i < buttonsPressed.length; ++i) {
if (buttonsPressed[i])
return true;
}
return false;
}

function runRAFUpdate() {
requestAnimationFrame(update);
}
Expand All @@ -63,13 +70,7 @@

setButtons();

if (isBlack) {
document.body.style.backgroundColor = 'white';
isBlack = false;
} else {
document.body.style.backgroundColor = 'black';
isBlack = true;
}
document.body.style.backgroundColor = oneButtonPressed() ? 'black' : 'white';

runRAFUpdate();
}
Expand Down

0 comments on commit 8a393e5

Please sign in to comment.