2022-05-16 13:53:20 +00:00
|
|
|
//! Prints mouse button events.
|
|
|
|
|
2024-07-01 14:27:21 +00:00
|
|
|
use bevy::{
|
|
|
|
input::mouse::{AccumulatedMouseMotion, AccumulatedMouseScroll},
|
|
|
|
prelude::*,
|
|
|
|
};
|
2020-06-05 06:49:36 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2020-11-03 03:01:17 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
2024-07-01 14:27:21 +00:00
|
|
|
.add_systems(Update, (mouse_click_system, mouse_move_system))
|
2020-06-05 06:49:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This system prints messages when you press or release the left mouse button:
|
2023-12-06 20:32:34 +00:00
|
|
|
fn mouse_click_system(mouse_button_input: Res<ButtonInput<MouseButton>>) {
|
2020-06-05 06:57:39 +00:00
|
|
|
if mouse_button_input.pressed(MouseButton::Left) {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("left mouse currently pressed");
|
2020-06-05 06:57:39 +00:00
|
|
|
}
|
2020-06-15 19:47:35 +00:00
|
|
|
|
2020-06-05 06:49:36 +00:00
|
|
|
if mouse_button_input.just_pressed(MouseButton::Left) {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("left mouse just pressed");
|
2020-06-05 06:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if mouse_button_input.just_released(MouseButton::Left) {
|
2021-04-22 23:30:48 +00:00
|
|
|
info!("left mouse just released");
|
2020-06-05 06:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-01 14:27:21 +00:00
|
|
|
|
|
|
|
// This system prints messages when you finish dragging or scrolling with your mouse
|
|
|
|
fn mouse_move_system(
|
|
|
|
accumulated_mouse_motion: Res<AccumulatedMouseMotion>,
|
|
|
|
accumulated_mouse_scroll: Res<AccumulatedMouseScroll>,
|
|
|
|
) {
|
|
|
|
if accumulated_mouse_motion.delta != Vec2::ZERO {
|
|
|
|
let delta = accumulated_mouse_motion.delta;
|
|
|
|
info!("mouse moved ({}, {})", delta.x, delta.y);
|
|
|
|
}
|
|
|
|
if accumulated_mouse_scroll.delta != Vec2::ZERO {
|
|
|
|
let delta = accumulated_mouse_scroll.delta;
|
|
|
|
info!("mouse scrolled ({}, {})", delta.x, delta.y);
|
|
|
|
}
|
|
|
|
}
|