diff --git a/src/bevy_plugin.rs b/src/bevy_plugin.rs index bbdbd27..4d77db2 100644 --- a/src/bevy_plugin.rs +++ b/src/bevy_plugin.rs @@ -1,4 +1,4 @@ -use bevy::{prelude::*, window::CursorOptions}; +use bevy::prelude::*; /// Overrides the default Bevy plugins and configures things like the screen settings. pub(super) fn plugin(app: &mut App) { @@ -6,13 +6,6 @@ pub(super) fn plugin(app: &mut App) { DefaultPlugins.set(WindowPlugin { primary_window: Window { title: "Among Me".into(), - // This will spawn an invisible window - // The window will be made visible in the make_visible() system after 3 frames. - // This is useful when you want to avoid the white window that shows up before the GPU is ready to render the app. - cursor_options: CursorOptions { - visible: false, - ..default() - }, ..default() } .into(), diff --git a/src/player.rs b/src/player.rs index ea3310f..06bf49d 100644 --- a/src/player.rs +++ b/src/player.rs @@ -6,7 +6,7 @@ use crate::{ }; use bevy::{ input::mouse::AccumulatedMouseMotion, pbr::NotShadowCaster, prelude::*, - render::view::RenderLayers, + render::view::RenderLayers, window::PrimaryWindow, }; #[derive(Debug, Component)] @@ -24,7 +24,7 @@ impl Default for CameraSensitivity { struct WorldModelCamera; pub fn plugin(app: &mut App) { - app.add_systems(OnEnter(GameState::Playing), init_player) + app.add_systems(OnEnter(GameState::Playing), (init_player, hide_cursor)) .add_systems(Update, move_camera.run_if(in_state(GameState::Playing))) .add_systems( RunFixedMainLoop, @@ -97,9 +97,14 @@ pub fn init_player( )); }); } +fn hide_cursor(mut windows: Query<&mut Window, With>) { + // Query returns one window typically. + for mut window in windows.iter_mut() { + window.cursor_options.visible = false; + } +} -use std::f32::consts::FRAC_PI_2; -const PITCH_LIMIT: f32 = FRAC_PI_2 - 0.01; +const PITCH_LIMIT: f32 = std::f32::consts::FRAC_PI_2 - 0.01; pub fn move_camera( accumulated_mouse_motion: Res,