mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
c313e21d65
# Objective - Update `wgpu` to 0.14.0, `naga` to `0.10.0`, `winit` to 0.27.4, `raw-window-handle` to 0.5.0, `ndk` to 0.7. ## Solution --- ## Changelog ### Changed - Changed `RawWindowHandleWrapper` to `RawHandleWrapper` which wraps both `RawWindowHandle` and `RawDisplayHandle`, which satisfies the `impl HasRawWindowHandle and HasRawDisplayHandle` that `wgpu` 0.14.0 requires. - Changed `bevy_window::WindowDescriptor`'s `cursor_locked` to `cursor_grab_mode`, change its type from `bool` to `bevy_window::CursorGrabMode`. ## Migration Guide - Adjust usage of `bevy_window::WindowDescriptor`'s `cursor_locked` to `cursor_grab_mode`, and adjust its type from `bool` to `bevy_window::CursorGrabMode`.
29 lines
820 B
Rust
29 lines
820 B
Rust
//! Demonstrates how to grab and hide the mouse cursor.
|
|
|
|
use bevy::prelude::*;
|
|
use bevy::window::CursorGrabMode;
|
|
|
|
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.primary_mut();
|
|
if mouse.just_pressed(MouseButton::Left) {
|
|
window.set_cursor_visibility(false);
|
|
window.set_cursor_grab_mode(CursorGrabMode::Locked);
|
|
}
|
|
if key.just_pressed(KeyCode::Escape) {
|
|
window.set_cursor_visibility(true);
|
|
window.set_cursor_grab_mode(CursorGrabMode::None);
|
|
}
|
|
}
|