diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..662ce28c1c806c6b24879f66d017c28d7ecf91f6 --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +# 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 + +```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` + +```rust +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 | \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 66f3bd1f31e6e57a261c396b124ca941431ce2c8..d58ff5286d1540a5113dd6de4ec6f888c295192f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,15 +40,15 @@ pub fn started_running(state: Res<SplashState>) -> bool { state.is_changed() && state.is_running() } -pub struct AdventSplashPlugin<StateType: States> { +pub struct MicroSplashPlugin<StateType: States> { settings: SplashSettings<StateType>, } -impl<StateType: States> AdventSplashPlugin<StateType> { - pub fn with_settings(settings: SplashSettings<StateType>) -> AdventSplashPlugin<StateType> { +impl<StateType: States> MicroSplashPlugin<StateType> { + pub fn with_settings(settings: SplashSettings<StateType>) -> MicroSplashPlugin<StateType> { Self { settings } } } -impl<StateType: States + Copy> Plugin for AdventSplashPlugin<StateType> { +impl<StateType: States + Copy> Plugin for MicroSplashPlugin<StateType> { fn build(&self, app: &mut App) { app.init_resource::<SplashState>() .insert_resource(SplashTime(Duration::from_secs(5)))