2020-10-18 22:24:01 +03:00
|
|
|
use bevy::{input::touch::*, prelude::*};
|
|
|
|
|
|
|
|
fn main() {
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2020-11-02 19:01:17 -08:00
|
|
|
.add_plugins(DefaultPlugins)
|
2021-07-27 23:42:36 +00:00
|
|
|
.add_system(touch_system)
|
2020-10-18 22:24:01 +03:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn touch_system(touches: Res<Touches>) {
|
2020-10-18 13:20:42 -07:00
|
|
|
for touch in touches.iter_just_pressed() {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!(
|
2020-10-18 13:20:42 -07:00
|
|
|
"just pressed touch with id: {:?}, at: {:?}",
|
2020-11-30 20:14:08 -05:00
|
|
|
touch.id(),
|
|
|
|
touch.position()
|
2020-10-18 22:24:01 +03:00
|
|
|
);
|
2020-10-18 13:20:42 -07:00
|
|
|
}
|
2020-10-18 22:24:01 +03:00
|
|
|
|
2020-10-18 13:20:42 -07:00
|
|
|
for touch in touches.iter_just_released() {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!(
|
2020-10-18 13:20:42 -07:00
|
|
|
"just released touch with id: {:?}, at: {:?}",
|
2020-11-30 20:14:08 -05:00
|
|
|
touch.id(),
|
|
|
|
touch.position()
|
2020-10-18 13:20:42 -07:00
|
|
|
);
|
|
|
|
}
|
2020-10-18 22:24:01 +03:00
|
|
|
|
2020-10-18 13:20:42 -07:00
|
|
|
for touch in touches.iter_just_cancelled() {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("cancelled touch with id: {:?}", touch.id());
|
2020-10-18 13:20:42 -07:00
|
|
|
}
|
2020-10-18 22:24:01 +03:00
|
|
|
|
2020-10-18 13:20:42 -07: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 22:24:01 +03:00
|
|
|
}
|
|
|
|
}
|