Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to render .gif images? #1857

Closed
ocean-beach opened this issue Jul 26, 2022 · 4 comments
Closed

Is it possible to render .gif images? #1857

ocean-beach opened this issue Jul 26, 2022 · 4 comments

Comments

@ocean-beach
Copy link

ocean-beach commented Jul 26, 2022

Hi. I'm using bevy_egui https://github.com/mvlabat/bevy_egui that provides a Egui integration for the bevy game engine.

I'm trying to render simple Window with .gif animation.

fn load_assets(mut commands: Commands, assets: Res<AssetServer>) {
    commands.insert_resource(Images {
        example_img: assets.load("images/example.gif"),
        // example_img: assets.load("images/example.png") <---- png  images work as expected, but not .gif
    });
}
fn render(
    mut egui_context: ResMut<EguiContext>,
    images: Res<Images>,
) {
    let bevy_texture_id = egui_context.add_image(images.example_img.clone_weak());
    egui::Window::new("dialog")
        .resizable(false)
        .collapsible(false)
        .title_bar(false)
        .show(egui_context.ctx_mut(), |ui| {
            ui.add(egui::widgets::Image::new(bevy_texture_id, [300.0, 300.0]));
        });
}

It it possible to render .gif animation with Egui?

@emilk
Copy link
Owner

emilk commented Jul 29, 2022

It is possible, but you will have to run the animation yourself.

Load all frames, assign them all their own texture, then flip between them at the right interval (remember to use Context::request_repaint)

@Gui-Yom
Copy link

Gui-Yom commented Jul 31, 2022

@ocean-beach I have this working in one of my projects here : https://github.com/Gui-Yom/vibin/blob/26e1a89a193d16754a1e33bd495aa51cd9b886a1/src/main.rs

In this code, I schedule a repaint from another thread so I can get the timings right without impacting the UI itself. Though I'm not sure how you could integrate this with bevy.

@ocean-beach
Copy link
Author

Thanks a lot @emilk and @Gui-Yom

@zdimension
Copy link

Support for animated GIFs has been added in #4620.

@emilk emilk closed this as completed Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants