From 4134351d9b4d14a352c1eccff6dc334fda1593ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Mon, 19 Feb 2024 17:44:50 +0100 Subject: [PATCH] also look in just_pressed touches for position (#7743) # Objective - On some devices, UI buttons are not responsive ## Solution - On device with a slower frame rate, touch event can start and end in the frame rate - When looking for a touch position, also look into the `just_pressed` touches that are not cleared by the end event but only at the end of the frame Co-authored-by: Alice Cecile --- crates/bevy_input/src/touch.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/bevy_input/src/touch.rs b/crates/bevy_input/src/touch.rs index 9b6a61b2bc..984cc83e93 100644 --- a/crates/bevy_input/src/touch.rs +++ b/crates/bevy_input/src/touch.rs @@ -335,7 +335,13 @@ impl Touches { /// Retrieves the position of the first currently pressed touch, if any pub fn first_pressed_position(&self) -> Option { - self.pressed.values().next().map(|t| t.position) + // Looking for the position in `pressed`. If nothing is found, also look into `just_pressed` + // A touch can be in `just_pressed` but not in `pressed` if it ended in the same frame it started + self.pressed + .values() + .next() + .or_else(|| self.just_pressed.values().next()) + .map(|t| t.position) } /// Clears `just_pressed`, `just_released`, and `just_canceled` data for every touch input.