Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only update Touches resource when needed #12048

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions crates/bevy_input/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,23 +400,15 @@ impl Touches {
}
};
}

/// Clears the `just_pressed`, `just_released`, and `just_canceled` collections.
///
/// This is not clearing the `pressed` collection, because it could incorrectly mark
/// a touch input as not pressed even though it is pressed. This could happen if the
/// touch input is not moving for a single frame and would therefore be marked as
/// not pressed, because this function is called on every single frame no matter
/// if there was an event or not.
fn update(&mut self) {
self.just_pressed.clear();
self.just_released.clear();
self.just_canceled.clear();
}
}

/// Updates the [`Touches`] resource with the latest [`TouchInput`] events.
///
/// This is not clearing the `pressed` collection, because it could incorrectly mark a touch input
/// as not pressed even though it is pressed. This could happen if the touch input is not moving
/// for a single frame and would therefore be marked as not pressed, because this function is
/// called on every single frame no matter if there was an event or not.
///
/// ## Differences
///
/// The main difference between the [`TouchInput`] event and the [`Touches`] resource is that
Expand All @@ -425,7 +417,15 @@ pub fn touch_screen_input_system(
mut touch_state: ResMut<Touches>,
mut touch_input_events: EventReader<TouchInput>,
) {
touch_state.update();
if !touch_state.just_pressed.is_empty() {
touch_state.just_pressed.clear();
}
if !touch_state.just_released.is_empty() {
touch_state.just_released.clear();
}
if !touch_state.just_canceled.is_empty() {
touch_state.just_canceled.clear();
}

for event in touch_input_events.read() {
touch_state.process_touch_event(event);
Expand Down
Loading