diff --git a/src/game.rs b/src/game.rs index 7841c15..94c7822 100644 --- a/src/game.rs +++ b/src/game.rs @@ -619,7 +619,9 @@ fn check_achievements( } fn handle_window_focus( + mut local_paused: Local, mut settings: ResMut, + mut q_window: Query<&mut Window, With>, mut er_focus: EventReader, mut physicstime: ResMut>, ) { @@ -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; } }