pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.7k stars 321 forks source link

Animated GIF image loading #834

Closed CyberHawk09 closed 2 years ago

CyberHawk09 commented 3 years ago

Disclaimer!

I have never used Github before so please pardon me if I am not using the correct format or something

Enhancement request:

Is it possible to allow importing animated GIFs?

I was just wondering because when making art, it is easier for me to just make a GIF with my tool.

pvcraven commented 3 years ago

Not yet. Currently listed as one of the desired enhancements:

https://arcade.academy/enhancement_list.html#sprites

It is certainly do-able, and I don't think would be that hard to program.

einarf commented 3 years ago

The question is what this function should return. An array of textures?

pushfoo commented 3 years ago

Would it work if arcade.load_textures made the image_location_list argument optional when the source file passed is a gif?

einarf commented 3 years ago

Here's a snippet of my loader dumping frames into a vertical strip (texture array), Should be easy enough to tweak. We also have to remember that gifs also come as single images, but I think that already works with load_texture()?

# If the image is animated (like a gif anim) we convert it into a vertical strip
if hasattr(self.image, "is_animated") and self.image.is_animated:
    self.layers = self.image.n_frames
    anim = Image.new(
        self.image.palette.mode,
        (self.image.width, self.image.height * self.image.n_frames),
    )
    anim.putalpha(0)

    for frame_number in range(self.image.n_frames):
        self.image.seek(frame_number)
        frame = self._palette_to_raw(self.image, mode="RGBA")
        anim.paste(frame, (0, frame_number * self.image.height))

    self.image = anim

This can also potentially work with other animated formats.

einarf commented 2 years ago

We do actually have this now.