Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/input/touch_input.rs
6595 views
1
//! Displays touch presses, releases, and cancels.
2
3
use bevy::{input::touch::*, prelude::*};
4
5
fn main() {
6
App::new()
7
.add_plugins(DefaultPlugins)
8
.add_systems(Update, touch_system)
9
.run();
10
}
11
12
fn 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
}
39
40