Sprite Sheet Formats for Bevy
Create Bevy TextureAtlasLayouts from sprite sheet formats
⚠️ This is still a work in progress, expect breaking changes on every minor release ⚠️
Overview
To use sprite sheets within Bevy you have to create a TextureAtlasLayout, if the sprites are in grid form and are of equal size, then this is fairly straightforward to set up (see example), but sprite sheets come in different shapes and sizes and often times they a bit more complex.
While you can set up the texture atlas yourself, most likely you'll have all of the sprites and their positions defined in an accompanying metadata file.
At its core, this crate allows you to use the metadata file to build a TextureAtlasLayout for you.
Highlights
- Supported formats:
- JSON Array
- JSON Hash
- Choose a sprite by using the
Framecomponent with the name of frame you want from the sprite sheet on an entity` - Automatic loading of textures, if supported by the sprite sheet format.
Getting Started
- Add the
SpriteSheetPluginto your app.
use SpriteSheetPlugin;
...
app.add_plugins
...
- Using
Res<AssetServer>,loadthe sprite sheet file and corresponding texture and insert the handles onto an entity, along with theFramecomponent and a BevySpriteBundle.
⚠️ By default, automatic texture loading is turned off. If you want to enable this. Add the
SpriteSheetOptionscomponent and settexture_loadingtotrue
use ;
let sprite_sheet: = asset_server.load;
let image: = asset_server.load;
commands.spawn;
/// Using `bevy_mod_spritesheet::SpriteSheetBundle`
commands.spawn;
- The
Handle<TextureAtlasLayout>andTextureAtlaswill be created in the background and inserted on the entity. If the sprite doesn't render correctly, check the console for error messages.
Example
Check out the examples folder for ideas on usage.
Supported Bevy Versions
bevy |
bevy_mod_spritesheet |
|---|---|
| 0.14 | 0.3, main |
| 0.13 | 0.2 |
| 0.13 | 0.1 |