mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
handle multiple dpad touches
This commit is contained in:
parent
b9a67e6b0f
commit
3461052193
|
@ -222,9 +222,11 @@
|
|||
addSimpleButton(mobileStart, "Start");
|
||||
addSimpleButton(mobileSelect, "Select");
|
||||
|
||||
let previouslyPressedButtons = [];
|
||||
let previouslyPressedButtons = new Set();
|
||||
|
||||
const dpadMovement = (touch) => {
|
||||
const currentlyPressed = new Set();
|
||||
for (let touch of touches) {
|
||||
const target = touch.target.getBoundingClientRect();
|
||||
|
||||
const touchPoint = { x: touch.clientX, y: touch.clientY };
|
||||
|
@ -254,14 +256,19 @@
|
|||
const buttonsToPress =
|
||||
(buttonBoxMapping[touchedBox.y] ?? [])[touchedBox.x] ?? [];
|
||||
|
||||
for (let button of buttonsToPress) {
|
||||
currentlyPressed.add(button);
|
||||
}
|
||||
}
|
||||
|
||||
for (let oldButton of previouslyPressedButtons) {
|
||||
if (!buttonsToPress.includes(oldButton)) {
|
||||
if (!buttonsToPress.has(oldButton)) {
|
||||
releaseButton(oldButton);
|
||||
}
|
||||
}
|
||||
|
||||
for (let newButton of buttonsToPress) {
|
||||
if (!previouslyPressedButtons.includes(newButton)) {
|
||||
if (!previouslyPressedButtons.has(newButton)) {
|
||||
pressButton(newButton);
|
||||
}
|
||||
}
|
||||
|
@ -270,18 +277,19 @@
|
|||
};
|
||||
|
||||
mobileDpad.addEventListener("touchstart", (evt) =>
|
||||
dpadMovement(evt.targetTouches[0])
|
||||
dpadMovement(evt.targetTouches)
|
||||
);
|
||||
|
||||
mobileDpad.addEventListener("touchmove", (evt) =>
|
||||
dpadMovement(evt.targetTouches[0])
|
||||
dpadMovement(evt.targetTouches)
|
||||
);
|
||||
|
||||
mobileDpad.addEventListener("touchend", (evt) => {
|
||||
for (let oldButton of previouslyPressedButtons) {
|
||||
releaseButton(oldButton);
|
||||
}
|
||||
previouslyPressedButtons = [];
|
||||
dpadMovement(evt.targetTouches);
|
||||
});
|
||||
|
||||
mobileDpad.addEventListener("touchcancel", (evt) => {
|
||||
dpadMovement(evt.targetTouches);
|
||||
});
|
||||
|
||||
let mobileAbAPress = new Set();
|
||||
|
|
Loading…
Reference in a new issue