2020-10-18 19:24:01 +00:00
|
|
|
use bevy::{input::touch::*, prelude::*};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::build()
|
2020-11-03 03:01:17 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
2020-11-17 02:18:00 +00:00
|
|
|
.add_system(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() {
|
2020-10-18 19:24:01 +00:00
|
|
|
println!(
|
2020-10-18 20:20:42 +00:00
|
|
|
"just pressed touch with id: {:?}, at: {:?}",
|
|
|
|
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() {
|
|
|
|
println!(
|
|
|
|
"just released touch with id: {:?}, at: {:?}",
|
|
|
|
touch.id, touch.position
|
|
|
|
);
|
|
|
|
}
|
2020-10-18 19:24:01 +00:00
|
|
|
|
2020-10-18 20:20:42 +00:00
|
|
|
for touch in touches.iter_just_cancelled() {
|
|
|
|
println!("cancelled touch with id: {:?}", touch.id);
|
|
|
|
}
|
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() {
|
|
|
|
println!("active touch: {:?}", touch);
|
|
|
|
println!(" just_pressed: {}", touches.just_pressed(touch.id));
|
2020-10-18 19:24:01 +00:00
|
|
|
}
|
|
|
|
}
|