reset password
Author Message
disrael
Posts: 44
Posted 23:07 May 12, 2015 |

Has anyone been able to use GIFs in their game? If so, how?

NoCool14
Posts: 2
Posted 01:17 May 13, 2015 |

Where in the game do you want to use GIFS? I think you cannot use animated GIFS

Otherwise you can load it just like any image:

# Don't forget to call the super constructor when extending pygame.sprite
        super().__init__();

#loads the image
        self.image = pygame.image.load("image.gif").convert()
       
 # Set the color that should be transparent if it does not have alpha set
        self.image.set_colorkey(pygame.Color(255,255,255))

 

Last edited by NoCool14 at 01:17 May 13, 2015.
disrael
Posts: 44
Posted 01:19 May 13, 2015 |

It wouldn't be a sprite necessarily. The idea would be for it to be a background image for the duration of the gif.It is animated. So, animated gifs are a no go then?

kknaur
Posts: 540
Posted 07:18 May 13, 2015 |

Pygame does not support animated gifs.  You might be able to use this 3rd party library which someone wrote and posted on the Pygame website.  Fair warning, the author says it does not work with all GIFs and will garble or completely drop random frames on certain GIFs. 

http://ajaxvm.com/downloads/GIFImage.py

EDIT: Actually strike that.  GIFImage.py requires the use of PIL (Python Imaging Library), but PIL does not have an updated version for Python 3.4.  I cannot find any other solutions other than using a sprite sheet for animation.

Last edited by kknaur at 07:25 May 13, 2015.