From 7afa21d3f8cd471456872c5721ba7ca6e6357a70 Mon Sep 17 00:00:00 2001 From: Will Hart Date: Sun, 11 Aug 2024 15:09:32 +1000 Subject: [PATCH] Splash screen allows exiting early (with escape key) (#257) This PR allows the player to exit the splash screen at any time by hitting `KeyCode::escape`. --- Previously this PR also contained code for displaying multiple splash screens, but after discussion that will be migrated to an example in the bevy repository. --------- Co-authored-by: Ben Frankel --- src/screens/splash.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/screens/splash.rs b/src/screens/splash.rs index fd40a6de..1a22c34c 100644 --- a/src/screens/splash.rs +++ b/src/screens/splash.rs @@ -1,6 +1,7 @@ //! A splash screen that plays briefly at startup. use bevy::{ + input::common_conditions::input_just_pressed, prelude::*, render::texture::{ImageLoaderSettings, ImageSampler}, }; @@ -35,12 +36,23 @@ pub(super) fn plugin(app: &mut App) { ) .run_if(in_state(Screen::Splash)), ); + + // Exit the splash screen early if the player hits escape. + app.add_systems( + Update, + exit_splash_screen + .run_if(input_just_pressed(KeyCode::Escape).and_then(in_state(Screen::Splash))), + ); } const SPLASH_BACKGROUND_COLOR: Color = Color::srgb(0.157, 0.157, 0.157); const SPLASH_DURATION_SECS: f32 = 1.8; const SPLASH_FADE_DURATION_SECS: f32 = 0.6; +fn exit_splash_screen(mut next_screen: ResMut>) { + next_screen.set(Screen::Loading); +} + fn spawn_splash(mut commands: Commands, asset_server: Res) { commands .ui_root()