Skip to content

Chocorean/bevy-easy-gif

Repository files navigation

bevy-easy-gif 🐸

License: Apache License: MIT Documentation 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 version 0.16 - 0.18
Gif3d ✔️
GifDespawn ✔️
GifNode ✔️
Gif ✔️

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

bevy bevy-easy-gif
0.18 0.3.0
0.17 0.2.1
0.16 0.1.5

Tests

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

About

Bevy crate for easy GIF spawning in 2D environments

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Contributors