release cursor when alt-tabbing out of the game
This commit is contained in:
parent
7412eb082f
commit
c0bb39958a
24
src/game.rs
24
src/game.rs
|
@ -619,7 +619,9 @@ fn check_achievements(
|
|||
}
|
||||
|
||||
fn handle_window_focus(
|
||||
mut local_paused: Local<bool>,
|
||||
mut settings: ResMut<Settings>,
|
||||
mut q_window: Query<&mut Window, With<PrimaryWindow>>,
|
||||
mut er_focus: EventReader<bevy::window::WindowFocused>,
|
||||
mut physicstime: ResMut<Time<Physics>>,
|
||||
) {
|
||||
|
@ -627,9 +629,23 @@ fn handle_window_focus(
|
|||
settings.window_focused = event.focused;
|
||||
}
|
||||
|
||||
if settings.is_game_running() {
|
||||
physicstime.unpause();
|
||||
} else {
|
||||
physicstime.pause();
|
||||
let paused = !settings.is_game_running();
|
||||
|
||||
if paused != *local_paused {
|
||||
if paused {
|
||||
physicstime.pause();
|
||||
} else {
|
||||
physicstime.unpause();
|
||||
}
|
||||
|
||||
for mut window in &mut q_window {
|
||||
window.cursor.grab_mode = if paused {
|
||||
bevy::window::CursorGrabMode::None
|
||||
} else {
|
||||
bevy::window::CursorGrabMode::Locked
|
||||
};
|
||||
window.cursor.visible = paused;
|
||||
}
|
||||
*local_paused = paused;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue