/bevy_mod_ui_texture_atlas_image

bevy plugin for displaying images from a texture atlas in the bevy UI

Primary LanguageRustMIT LicenseMIT

bevy_mod_ui_texture_atlas_image

crates.io MIT/Apache 2.0 crates.io

Draw images from texture atlases with the Bevy UI.

image

  • Version 0.3 supports Bevy 0.10
  • Version 0.2 supports Bevy 0.9
  • Version 0.1 supports Bevy 0.8

Details

To use this crate, add its dependency to your project's Cargo.toml:

bevy_mod_ui_texture_atlas_image = "0.3"

or use Cargo:

cargo add bevy_mod_ui_texture_atlas_image

Then add the UiAtlasImagePlugin plugin to your Bevy App:

use bevy_mod_ui_texture_atlas_image::*;

fn main () {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(UiAtlasImagePlugin)
        // ..rest of app
        .run()
}

Now you can spawn an AtlasImageBundle to draw images from a TextureAtlas with the Bevy UI.

commands
    .spawn(AtlasImageBundle {
        atlas_image: UiAtlasImage { 
            atlas: texture_atlas_handle.clone(),
            index: 5
        },
        ..Default::default()
    });

The only difference between an AtlasImageBundle and an ImageBundle is that instead of an image field with type UiImage, it has an atlas_image field with type UiAtlasImage.

Examples

  • Displaying a single image from a texture atlas:
    cargo --run --example minimal
    
  • Displaying three tiles from a texture atlas grid alongside the atlas's source image:
    cargo --run --example tiles