touch_input/
touch_input.rs

1//! Displays touch presses, releases, and cancels.
2
3use bevy::{input::touch::*, prelude::*};
4
5fn main() {
6    App::new()
7        .add_plugins(DefaultPlugins)
8        .add_systems(Update, touch_system)
9        .run();
10}
11
12fn touch_system(touches: Res<Touches>) {
13    for touch in touches.iter_just_pressed() {
14        info!(
15            "just pressed touch with id: {}, at: {}",
16            touch.id(),
17            touch.position()
18        );
19    }
20
21    for touch in touches.iter_just_released() {
22        info!(
23            "just released touch with id: {}, at: {}",
24            touch.id(),
25            touch.position()
26        );
27    }
28
29    for touch in touches.iter_just_canceled() {
30        info!("canceled touch with id: {}", touch.id());
31    }
32
33    // you can also iterate all current touches and retrieve their state like this:
34    for touch in touches.iter() {
35        info!("active touch: {touch:?}");
36        info!("  just_pressed: {}", touches.just_pressed(touch.id()));
37    }
38}