From fc29bc27fd1c6904143fc24fbcf5ca629ec491c6 Mon Sep 17 00:00:00 2001 From: Maicon Santana Date: Mon, 6 Jan 2025 10:29:24 +0000 Subject: [PATCH] Fix Touch pointCount reduction (#4661) --- src/platforms/rcore_web.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index 9fd2afb5..78fd46f5 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -1812,7 +1812,23 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) { - CORE.Input.Touch.pointCount--; + // Identify the EMSCRIPTEN_EVENT_TOUCHEND and remove it from the list + for (int i = 0; i < CORE.Input.Touch.pointCount; i++) + { + if (touchEvent->touches[i].isChanged) + { + // Move all touch points one position up + for (int j = i; j < CORE.Input.Touch.pointCount - 1; j++) + { + CORE.Input.Touch.pointId[j] = CORE.Input.Touch.pointId[j + 1]; + CORE.Input.Touch.position[j] = CORE.Input.Touch.position[j + 1]; + } + // Decrease touch points count to remove the last one + CORE.Input.Touch.pointCount--; + break; + } + } + // Clamp pointCount to avoid negative values if (CORE.Input.Touch.pointCount < 0) CORE.Input.Touch.pointCount = 0; }