Skip to main content

Crate bevy_easy_gif

Crate bevy_easy_gif 

Source
Expand description

Frog

.gif files asset loading for the bevy game engine.

bevy-easy-gif provides a super easy way to load GIF files using Bevy’s AssetLoader. Under the hood, each frame is extracted and loaded by the asset loader as an Image. The GIF metadata is also partially saved. The duration of each frame is obviously very important, but how the GIF should loop matters as well. If provided, bevy-easy-gif will read the repeat metadata provided by the gif crate, and respect it. That means there is almost zero configuration to do code-wise if your GIF files are properly build (yes, I’m looking at you Aseprite).

§Example

Add the gif plugin to your app:

use bevy::prelude::*;
use bevy_easy_gif::*;

App::default()
    .add_plugins(DefaultPlugins)
    .add_plugins(GifPlugin)
    .run();

Spawn a Gif:

let handle = asset_loader.load("animated.gif") // located in ./assets/
commands.spawn(Gif { handle });

Gif leverages the required components feature of Bevy 0.15 and automagically spawns alongside itself a Sprite and a GifPlayer. The trick is to change the image field of the sprite at very specific timings, mimicking the behavior of a GIF file. GifPlayer is an internal state which controls what to show, when to show it, and when to stop.

The examples cover pretty much all there is to know.

Structs§

Gif
Entity used to spawn a Sprite with an animated texture. This is the main and might be the only struct you will use from this crate.
Gif3d
3d component to display a gif file on a 3d object.
GifAsset
Contains the data of a GIF
GifDespawn
Insert this component next to a non-infinite Gif to despawn the entity when its loops are over.
GifNode
Ui component to display a gif file.
GifPlayer
Internal state of a Gif. Store the current frame index, its associated timer, and the number of remaining repetitions, minus the one currently running.
GifPlugin