Confine the cursor to a window
Bevy version: 0.16Last updated:
Set the CursorOptions
on the Window
to CursorGrabMode::Confied
.
use bevy::prelude::*;
use bevy::window::{CursorGrabMode, CursorOptions};
fn main() {
let window = Window {
cursor_options: CursorOptions {
grab_mode: CursorGrabMode::Confined, // Enable cursor confinement
..default()
},
..default()
};
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(window),
..default()
}))
.run();
}
This currently has poor cross-platform support and won't work on macOS.