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

micro_bevy_splash

Bevy的简单一次性logo启动屏幕

1个不稳定版本

0.1.0 2024年5月18日

#1644 in 游戏开发

Apache-2.0

15KB
329

Micro Bevy Splash

Bevy的简单一次性logo启动屏幕插件

渲染启动屏幕logo,完成后可选过渡到另一个状态。

启动屏幕的基本用法是在加载资源时提供视觉兴趣。为了实现这一点,您可以执行以下流程

  1. 配置您的游戏状态,以便您有一个可以触发资源加载的状态,一个显示启动屏幕的状态,以及一个显示加载指示器的状态,如果有剩余的资源
  2. 预加载您的启动屏幕资源,然后触发其他资源的加载
  3. 通过插件设置指定 micro_bevy_splash 在启动状态中渲染,并在加载开始后过渡到该状态
  4. 通过插件设置指定加载屏幕状态为 micro_bevy_splash 的退出状态
  5. 在您的加载状态中,检查尚未加载的任何资源,并为它们渲染加载指示器 - 用户可能跳过启动屏幕,或者加载可能比您的启动屏幕持续时间更长,因此您应该假设在从启动状态过渡时会有一些资源没有完全加载

用法

在项目的 Cargo.toml 中包含 micro_bevy_splash

[dependencies]
micro_bevy_splash = "0.1.0"

然后配置插件,包括要渲染的状态和要过渡到的状态。这些状态可以是实现来自 bevyStates 特性的任何类型,但这两个状态必须是同一具体类型 - 通常是一个 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兼容性

micro_bevy_splash bevy
0.1.0 0.13.x

依赖项

~38–75MB
~1.5M SLoC