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 sprite sheet example.png for our game,

/assets/example.png

that has sprites with irregular sizes and positions.

How to load the sprite sheet

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

( "example.png", Sprites ([ ( x: 18, y: 19, w: 46, h: 48 ), ( x: 93, y: 108, w: 32, h: 31 ), ( x: 176, y: 34, w: 20, h: 34 ), ]) ) Alternatively, you can give each sprite a unique name that can be used to look up their TextureAtlas index.

( "example.png", NamedSprites ([ { name: "yellow", x: 18, y: 19, w: 46, h: 48 }, { name: "face", x: 93, y: 108, w: 32, h: 31 }, { name: "patches", x: 176, y: 34, w: 20, h: 34 }, ]) ) * You can call the manifest anything you like, not only manifest.ron. * The file path is relative to the root assets folder, not to the manifest file. * The sprites are in a list not a map to preserve ordering. The sprite indices in the ouput ordered implicitly according to the order of the input list. * Use name: "" to skip naming a sprite in a NamedSprites list 2. Add the BHTAL 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

/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"