Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielfeather/bevy_mod_spritesheet
Create Bevy TextureAtlases from common spritesheet formats
https://github.com/danielfeather/bevy_mod_spritesheet
bevy spritesheets texture-atlas
Last synced: 3 months ago
JSON representation
Create Bevy TextureAtlases from common spritesheet formats
- Host: GitHub
- URL: https://github.com/danielfeather/bevy_mod_spritesheet
- Owner: danielfeather
- License: mit
- Created: 2024-03-29T17:27:49.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-12T11:38:07.000Z (5 months ago)
- Last Synced: 2024-10-01T14:36:22.178Z (3 months ago)
- Topics: bevy, spritesheets, texture-atlas
- Language: Rust
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Sprite Sheet Formats for Bevy
![Build and Test Workflow](https://github.com/danielfeather/bevy_mod_spritesheet/actions/workflows/build-and-test.yml/badge.svg?event=push)
[![crates.io](https://img.shields.io/crates/v/bevy_mod_spritesheet)](https://crates.io/crates/bevy_mod_spritesheet)
[![docs.rs](https://docs.rs/bevy_mod_spritesheet/badge.svg)](https://docs.rs/bevy_mod_spritesheet)Create [Bevy](https://github.com/bevyengine/bevy) `TextureAtlasLayout`s 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](https://github.com/bevyengine/bevy/blob/release-0.13.2/examples/2d/sprite_sheet.rs)), 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 `Frame` component 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
1. Add the `SpriteSheetPlugin` to your app.
```rs
use bevy_mod_spritesheet::SpriteSheetPlugin;
...
app.add_plugins(SpriteSheetPlugin)
...
```2. Using `Res`, `load` the sprite sheet file and corresponding texture and insert the handles onto an entity, along with the `Frame` component and a Bevy `SpriteBundle`.
> ⚠️ By default, automatic texture loading is turned off. If you want to enable this. Add the `SpriteSheetOptions` component and set `texture_loading` to `true`
```rs
use bevy_mod_spritesheet::{format::json::array::JsonArray, Frame, SpriteSheet, SpriteSheetBundle, SpriteSheetOptions, SpriteSheetPlugin};let sprite_sheet: Handle> = asset_server.load("gabe-idle-run.json");
let image: Handle = asset_server.load("gabe-idle-run.png");commands.spawn((
SpriteBundle {
texture: image,
sprite: Sprite {
custom_size: Some(Vec2::splat(500.0)),
..default()
},
..default()
},
Frame::name("gabe-idle-run 6.png".into()),
sprite_sheet,
));/// Using `bevy_mod_spritesheet::SpriteSheetBundle`
commands.spawn((
SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::splat(500.0)),
..default()
},
..default()
},
SpriteSheetBundle {
frame: Frame::name("gabe-idle-run 6.png".into()),
options: SpriteSheetOptions {
texture_loading: true,
},
sprite_sheet,
},
));```
3. The `Handle` and `TextureAtlas` will 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|