mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
handle many button presses and fix to use targetTouches
This commit is contained in:
parent
3a1f1691f9
commit
b9a67e6b0f
|
@ -270,11 +270,11 @@
|
|||
};
|
||||
|
||||
mobileDpad.addEventListener("touchstart", (evt) =>
|
||||
dpadMovement(evt.touches[0])
|
||||
dpadMovement(evt.targetTouches[0])
|
||||
);
|
||||
|
||||
mobileDpad.addEventListener("touchmove", (evt) =>
|
||||
dpadMovement(evt.touches[0])
|
||||
dpadMovement(evt.targetTouches[0])
|
||||
);
|
||||
|
||||
mobileDpad.addEventListener("touchend", (evt) => {
|
||||
|
@ -284,8 +284,10 @@
|
|||
previouslyPressedButtons = [];
|
||||
});
|
||||
|
||||
let mobileAbAPress = undefined;
|
||||
const mobileAbMovement = (touch) => {
|
||||
let mobileAbAPress = new Set();
|
||||
const mobileAbMovement = (touches) => {
|
||||
const currentTouches = new Set();
|
||||
for (let touch of touches) {
|
||||
const target = touch.target.getBoundingClientRect();
|
||||
|
||||
const touchPoint = { x: touch.clientX, y: touch.clientY };
|
||||
|
@ -302,39 +304,39 @@
|
|||
};
|
||||
|
||||
const aPress = relativePosition.x > relativePosition.y;
|
||||
|
||||
if (aPress !== mobileAbAPress) {
|
||||
if (mobileAbAPress === true) {
|
||||
releaseButton("A");
|
||||
} else if (mobileAbAPress === false) {
|
||||
releaseButton("B");
|
||||
}
|
||||
}
|
||||
if (aPress) {
|
||||
pressButton("A");
|
||||
} else {
|
||||
pressButton("B");
|
||||
currentTouches.add(aPress ? "A" : "B");
|
||||
}
|
||||
|
||||
mobileAbAPress = aPress;
|
||||
for (let oldTouch of mobileAbAPress) {
|
||||
if (!currentTouches.has(oldTouch)) {
|
||||
console.log("Release", oldTouch);
|
||||
releaseButton(oldTouch);
|
||||
}
|
||||
}
|
||||
|
||||
for (let newTouch of currentTouches) {
|
||||
if (!mobileAbAPress.has(newTouch)) {
|
||||
console.log("Press", newTouch);
|
||||
pressButton(newTouch);
|
||||
}
|
||||
}
|
||||
mobileAbAPress = currentTouches;
|
||||
};
|
||||
|
||||
mobileAb.addEventListener("touchstart", (evt) =>
|
||||
mobileAbMovement(evt.touches[0])
|
||||
);
|
||||
mobileAb.addEventListener("touchstart", (evt) => {
|
||||
mobileAbMovement(evt.targetTouches);
|
||||
});
|
||||
|
||||
mobileAb.addEventListener("touchmove", (evt) =>
|
||||
mobileAbMovement(evt.touches[0])
|
||||
);
|
||||
mobileAb.addEventListener("touchmove", (evt) => {
|
||||
mobileAbMovement(evt.targetTouches);
|
||||
});
|
||||
|
||||
mobileAb.addEventListener("touchend", (evt) => {
|
||||
if (mobileAbAPress === true) {
|
||||
releaseButton("A");
|
||||
} else if (mobileAbAPress === false) {
|
||||
releaseButton("B");
|
||||
}
|
||||
mobileAbMovement(evt.targetTouches);
|
||||
});
|
||||
|
||||
mobileAbAPress = undefined;
|
||||
mobileAb.addEventListener("touchcancel", (evt) => {
|
||||
mobileAbMovement(evt.targetTouches);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue