2022-05-16 13:53:20 +00:00
|
|
|
//! Displays touch presses, releases, and cancels.
|
|
|
|
|
2020-10-18 19:24:01 +00:00
|
|
|
use bevy::{input::touch::*, prelude::*};
|
|
|
|
|
|
|
|
fn main() {
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2020-11-03 03:01:17 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
2023-03-18 01:45:34 +00:00
|
|
|
.add_systems(Update, touch_system)
|
2020-10-18 19:24:01 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn touch_system(touches: Res<Touches>) {
|
2020-10-18 20:20:42 +00:00
|
|
|
for touch in touches.iter_just_pressed() {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!(
|
2020-10-18 20:20:42 +00:00
|
|
|
"just pressed touch with id: {:?}, at: {:?}",
|
2020-12-01 01:14:08 +00:00
|
|
|
touch.id(),
|
|
|
|
touch.position()
|
2020-10-18 19:24:01 +00:00
|
|
|
);
|
2020-10-18 20:20:42 +00:00
|
|
|
}
|
2020-10-18 19:24:01 +00:00
|
|
|
|
2020-10-18 20:20:42 +00:00
|
|
|
for touch in touches.iter_just_released() {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!(
|
2020-10-18 20:20:42 +00:00
|
|
|
"just released touch with id: {:?}, at: {:?}",
|
2020-12-01 01:14:08 +00:00
|
|
|
touch.id(),
|
|
|
|
touch.position()
|
2020-10-18 20:20:42 +00:00
|
|
|
);
|
|
|
|
}
|
2020-10-18 19:24:01 +00:00
|
|
|
|
2023-04-05 21:25:53 +00:00
|
|
|
for touch in touches.iter_just_canceled() {
|
2023-04-08 16:22:46 +00:00
|
|
|
info!("canceled touch with id: {:?}", touch.id());
|
2020-10-18 20:20:42 +00:00
|
|
|
}
|
2020-10-18 19:24:01 +00:00
|
|
|
|
2020-10-18 20:20:42 +00:00
|
|
|
// you can also iterate all current touches and retrieve their state like this:
|
|
|
|
for touch in touches.iter() {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("active touch: {:?}", touch);
|
|
|
|
info!(" just_pressed: {}", touches.just_pressed(touch.id()));
|
2020-10-18 19:24:01 +00:00
|
|
|
}
|
|
|
|
}
|