๐Ÿ“ฆ Chocorean / bevy-easy-gif

Bevy crate for easy GIF spawning in 2D environments

โ˜… 7 stars โ‘‚ 0 forks ๐Ÿ‘ 7 watching โš–๏ธ Apache License 2.0
๐Ÿ“ฅ Clone https://github.com/Chocorean/bevy-easy-gif.git
HTTPS git clone https://github.com/Chocorean/bevy-easy-gif.git
SSH git clone git@github.com:Chocorean/bevy-easy-gif.git
CLI gh repo clone Chocorean/bevy-easy-gif
Chocorean Chocorean update ci d951a32 3 months ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .cargo
๐Ÿ“ .github
๐Ÿ“ assets
๐Ÿ“ bin
๐Ÿ“ examples
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ Cargo.lock
๐Ÿ“„ Cargo.toml
๐Ÿ“„ CHANGELOG.md
๐Ÿ“„ LICENSE-APACHE
๐Ÿ“„ LICENSE-MIT
๐Ÿ“„ README.md
๐Ÿ“„ README.md

bevy-easy-gif ๐Ÿธ

License License: MIT Doc Crate Bevy tracking CI testing

frog

A 0-work 0-pain way to display GIF files in your Bevy games.

[!WARNING]
This project is still in the early stages of development.

Usage

This is all it takes in a system to spawn a Sprite with an animated texture from a GIF file:

// It does require a `Camera2d` and the `GifPlugin`
fn spawn_gif(mut commands: Commands, asset_server: ResMut<AssetServer>) {
    let handle: Handle<GifAsset> = asset_server.load("frog_large.gif");
    commands.spawn(
        Gif { handle }
    );
}

There are also a few examples you can check for customization.

Features matrix

Bevy version0.160.17
Gif3d:heavycheckmark::heavycheckmark:
GifDespawn:heavycheckmark::heavycheckmark:
GifNode:heavycheckmark::heavycheckmark:
Gif:heavycheckmark::heavycheckmark:

Why?

GIF files are by default not supported by Bevy's asset loader (only the first frame is loaded).

The current workaround is to export GIF files as atlases, use a TextureAtlas with a Sprite, and then manually animate the sprite by changing the atlas properties.

I wanted a drop-in solution to load GIF files and display them to way they show in any other GIF viewer. Respecting the timing and the repetitions of the GIF files is supported too.

How?

This crate leverages required components introduced in Bevy 0.15. Spawning a Gif component will automatically add a Sprite alongside, and the GifPlugin will then animate the Sprite to display the frames of the GIF file. The Gif components also carry a GifPlayer, which describe the internal state of the entity: the current frame to display, and how long it should stay displayed. The GifPlayer's timer is automatically configured, after reading the GIF metadata.

Bevy support

bevybevy-easy-gif
0.170.2.0
0.160.1.5

Tests

To test the library, run: cargo test --lib. To see an example using wasm, run bin/wasm, and open your browser.