Bevy Heterogenous Texture Atlas Loader

Bevy Heterogenous Texture Atlas Loader allows you to load heterogenous texture atlases according to a RON file manifest.

This works (as far as I can tell), but the implementation could be improved a lot. Any suggestions would be very welcome.

Suports Bevy 0.6

#

Usage Example

We have a beautiful sprite sheet example.png for our game:

/assets/example.png

But the sprites have irregular sizes and positions.

How to load it:

  1. Create a manifest.ron manifest file in your assets folder

( path: "example.png", rects: [ ("rothko", 16, 64, 19, 67), ("handsome face", 93, 125, 108, 139), ("cyan and peaches", 176, 196, 34, 68), ] ) * You can call the manifest anything you like, not only manifest.ron. * The path is relative to the root assets folder, not to the manifest file. * The rects coords are in order minx, maxx, miny, maxy. * rects is a list not a map to preserve ordering. The sprite indices in the text atlas are ordered implicitly according to the order of the rects list. * If you don't need to look up the sprites by name, use an empty string: rects: [ ("", 16, 64, 19, 67), ...

  1. Add the dependency to your Cargo.toml

bevy_heterogeneous_texture_atlas_loader = "0.1.2"

  1. Write the app

```rust use bevy::prelude::; use bevy_heterogeneous_texture_atlas_loader::;

fn setup( mut commands: Commands, assetserver: Res, ) { commands.spawnbundle(OrthographicCameraBundle::new2d()); let manifest: Handle = assetserver.load("manifest.ron"); commands.insert_resource(manifest); }

fn onatlasloaded( mut commands: Commands, mut events: EventReader, atlases: Res>, ) { for event in events.iter() { let atlas = atlases.get(&event.atlas).unwrap(); commands .spawnbundle(SpriteBundle { texture: atlas.texture.clone(), ..Default::default() }); for i in 0..3 { let target = -200. * Vec3::X + (100. * i as f32 - 100.) * Vec3::Y; commands .spawnbundle(SpriteSheetBundle { sprite: TextureAtlasSprite::new(i), textureatlas: event.atlas.clone(), transform: Transform::fromtranslation(target), ..Default::default() }); } } }

fn main() { App::new() .addplugins(DefaultPlugins) .addplugin(HeterogeneousTextureAtlasLoaderPlugin) .addstartupsystem(setup) .addsystem(onatlas_loaded) .run(); } ``` 4. Result, lovely

/assets/example.png

#

FAQ

Can I use this with bevyassetloader?

I wish

"Manifest not found"?

You need to store a strong handle to the manifest in a resource or something, otherwise it will be dropped before the texture atlas is created.

Why are the names for everything so long?

Shorter than "Bevy Heterogenous Texture Atlas Ron Manifest Asynchronous Loader"