Skip to content

djeedai/bevy_bootloader

🚥 Bevy Bootloader

License: MIT/Apache Doc Crate Build Status Coverage Status Bevy tracking

App startup and resource management plugin for the Bevy game engine.

Usage

Dependency

Add to Cargo.toml:

[dependencies]
bevy_bootloader = "0.1"

System setup

Add the BootloaderPlugin to your app:

App::default()
    .add_plugins(DefaultPlugins)
    .add_plugin(BootloaderPlugin)
    .run();

Queue boot-time critical assets, and insert a BootBundle:

// Queue boot-time resources
let mut loader = Loader::new();
loader.enqueue("logo.png");
loader.enqueue("music.ogg");
loader.submit();

// Insert a boot bundle
commands.spawn_bundle(BootBundle::new(loader));

Check the boot state with either of Boot::progress(), Boot::smoothed_progress(), or Loader::is_done(). For example, use Boot::smoothed_progress() to smoothly update a progress bar made of a Sprite:

fn update_progress_bar(
    boot_query: Query<&Boot>,
    mut sprite_query: Query<(&mut Transform, &mut Sprite), With<ProgressBar>>,
) {
    if let Ok(boot) = boot_query.get_single() {
        // Update the progress bar based on the fraction of assets already loaded, smoothed
        // with a snappy animation to be visually pleasant without too much artifically
        // delaying the boot sequence.
        let smoothed_progress = boot.smoothed_progress();
        let (mut transform, mut sprite) = sprite_query.single_mut();
        let size = PROGRESS_BAR_SIZE * smoothed_progress;
        // The sprite is a rect centered at the transform position, so move by half size to
        // keep aligned to the left while width grows.
        transform.translation.x = (size - PROGRESS_BAR_SIZE) / 2.;
        sprite.custom_size = Some(Vec2::new(size, PROGRESS_BAR_THICKNESS));
    }
}

See the bootloader example for the full code.

Compatible Bevy versions

The main branch is compatible with the latest Bevy release.

Compatibility of bevy_bootloader versions:

bevy_bootloader bevy
0.1 0.6

Due to the fast-moving nature of Bevy and frequent breaking changes, and the limited resources to maintan 🚥 Bevy Bootloader, the main (unreleased) Bevy branch is not supported.

About

App startup and resource management plugin for the Bevy game engine.

Topics

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE2
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages