mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 14:40:19 +00:00
6ce8e50068
Fixes #4094
26 lines
709 B
Rust
26 lines
709 B
Rust
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_system(grab_mouse)
|
|
.run();
|
|
}
|
|
|
|
// This system grabs the mouse when the left mouse button is pressed
|
|
// and releases it when the escape key is pressed
|
|
fn grab_mouse(
|
|
mut windows: ResMut<Windows>,
|
|
mouse: Res<Input<MouseButton>>,
|
|
key: Res<Input<KeyCode>>,
|
|
) {
|
|
let window = windows.get_primary_mut().unwrap();
|
|
if mouse.just_pressed(MouseButton::Left) {
|
|
window.set_cursor_visibility(false);
|
|
window.set_cursor_lock_mode(true);
|
|
}
|
|
if key.just_pressed(KeyCode::Escape) {
|
|
window.set_cursor_visibility(true);
|
|
window.set_cursor_lock_mode(false);
|
|
}
|
|
}
|