Update gamepad.js (#855)

The objects traversed by the “foreach” method should be arrays, and the “Array.from()” method should be used to convert the traversal objects to arrays, ensuring that they run in some more restrictive browsers.
This commit is contained in:
赵彤刚 2024-07-14 13:13:11 +08:00 committed by GitHub
parent e8c774c748
commit 611a8c26d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -37,7 +37,7 @@ class GamepadHandler {
this.timeout = setTimeout(this.loop.bind(this), 10); this.timeout = setTimeout(this.loop.bind(this), 10);
} }
updateGamepadState() { updateGamepadState() {
const gamepads = this.getGamepads(); const gamepads = Array.from(this.getGamepads());
gamepads.forEach((gamepad, index) => { gamepads.forEach((gamepad, index) => {
if (!gamepad) return; if (!gamepad) return;
let hasGamepad = false; let hasGamepad = false;