Pygame Animated GIF Sprite
Simple usage
To get started, install the package for your project
pip install pygame-animatedgif
To use the class in your project first import the corresponding class
import pygame
from pygame_animatedgif import AnimatedGifSprite
Now you can create instances of the animated sprites in the following way
dog = AnimatedGifSprite((50, 50), "example/dog_drinking_milk.gif")
The first parameter given to the constructor are the x, y coordinates on your pygame screen where the sprite should be placed. The second parameter is a string giving the absolute or relative path to an animated GIF file.
To automatically handle drawing of the sprite, it must be added to a sprite group:
sprite_group = pygame.sprite.Group()
sprite_group.add(dog)
And finally, in the main game loop you only need to take care of updating drawing the sprite group once every frame.
pygame.init()
screen = pygame.display.set_mode((640, 480))
while True:
screen.fill((255,255,255))
sprite_group.update(screen)
sprite_group.draw(screen)
pygame.display.flip()
Complete API
Acknowledgments
RB[0] - Original implementation of a Python class for animated GIFs
Nick Sandau - Addition of several methods for a richer API in the extended GIFImage class