forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse_input.rs
43 lines (37 loc) · 1.31 KB
/
mouse_input.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! Prints mouse button events.
use bevy::{
input::mouse::{AccumulatedMouseMotion, AccumulatedMouseScroll},
prelude::*,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, (mouse_click_system, mouse_move_system))
.run();
}
// This system prints messages when you press or release the left mouse button:
fn mouse_click_system(mouse_button_input: Res<ButtonInput<MouseButton>>) {
if mouse_button_input.pressed(MouseButton::Left) {
info!("left mouse currently pressed");
}
if mouse_button_input.just_pressed(MouseButton::Left) {
info!("left mouse just pressed");
}
if mouse_button_input.just_released(MouseButton::Left) {
info!("left mouse just released");
}
}
// 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);
}
}