Skip to content

Commit

Permalink
Splash screen allows exiting early (with escape key) (#257)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
will-hart and benfrankel committed Aug 11, 2024
1 parent fc593b7 commit 7afa21d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/screens/splash.rs
Original file line number Diff line number Diff line change
@@ -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},
};
Expand Down Expand Up @@ -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<NextState<Screen>>) {
next_screen.set(Screen::Loading);
}

fn spawn_splash(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.ui_root()
Expand Down

0 comments on commit 7afa21d

Please sign in to comment.