#screen #splash #logo #assets #bevy #micro #one-shot

micro_bevy_splash

Simple, one-shot logo splash screen for Bevy

1 unstable release

0.1.0 May 18, 2024

#2196 in Game dev

Apache-2.0

15KB
329 lines

Micro Bevy Splash

A simple, one-shot logo splash screen plugin for Bevy

Render a splash screen logo with optional tweening that will subsequently transition to another state when complete.

A basic use case for splash screens is to provide visual interest while loading assets. To achieve this, you can perform the following flow:

  1. Configure your game states such that you have one to trigger asset loading, one in which the splash screen should be shown, and one that shows a loading indicator if there are any remaining assets
  2. Preload your splash screen assets, and then trigger the loading of your other assets
  3. Specify micro_bevy_splash to render in your splash state via the plugin settings, and transition to that state once loading has begun
  4. Specify the loading screen state as the exit state for micro_bevy_splash via the plugin settings
  5. In your loading state, check for any assets that haven't been loaded yet, and render a loading indicator for them - users may skip the splash screen, or loading might take longer than your splash duration, so you should assume that there will be some assets not fully loaded when transitioning away from the splash state

Usage

Include micro_bevy_splash in your project's Cargo.toml

[dependencies]
micro_bevy_splash = "0.1.0"

and then configure the plugin for your app, including what state to render in, and what state to transition to. The states can be any type that implements the States trait from bevy, but both states must be of the same concrete type - typically an enum

use micro_bevy_splash::{MicroSplashPlugin, SplashSettings};

// Import all of the usual bevy libraries here

#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, States, Default)]
enum AppState {
    Preload,
    Setup,
    Splash,
    Menu,
}

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins::default(),
            MicroSplashPlugin::with_settings(SplashSettings {
                // Specify when the plugin runs, and what it transitions to
                run_in: AppState::Splash,
                transition_to: AppState::Menu,
                // Specify the asset path that the default bevy asset server will
                // use to look up the splash logo to display, and the musical sting
                // that will play over the screen
                logo_path: String::from("splash/splash_clean.png"),
                sting_path: String::from("splash/sting.ogg"),
                // Allow users to press Space, Return, or Escape to skip to the exit state
                skip_on_input: true,
                // How long to stay on this screen. This differs from any time spent tweening
                // the assets, as you typically want to hang on a static view of the logo
                // for some short period of time
                duration: Duration::from_secs(3),
                // Specify tween values for animating the background colour and the logo colour
                // These can be specified independently, and providing `None` will not tween
                // that component
                bg_color_tween: Some((Color::Black, Color::Red)),
                tween_duration: Some(Duration::from_secs(2)),
                logo_color_tween: None,
            })
         ))
        .run();
}


Bevy Compatibility

micro_bevy_splash bevy
0.1.0 0.13.x

Dependencies

~41–78MB
~1.5M SLoC