1

How can I add a moving Gif in pygame for a simple loop? I tried normal image importing but the .gif was invisible. Any ideas on how to do this? I want to do it for a new game I'm making with the main characters legs moving and fire to move. I haven't tried sprites in pygame because image importing is easy enough and it has worked thus far for static images with maybe a change to face different directions

I've tried simply this:

img = pygame.image.load("img.gif")

I blit'd it onto the screen. Invisible. I tried it with a .PNG and it was visible.

HKVariant
  • 837
  • 10
  • 23

1 Answers1

2

Short answer: You cannot do that using pygame.image.load

Long answer: Yes, there is a work around.

  1. Extract each of the images from the gif (if on a Mac use this).
  2. Add all the image names to a list
  3. Using a for loop, load them all and put it in a dictionary                                                                   you can use another list for this instead, your choice.

img_names = [*my image names*]
all_imgs = {}
for img in img_names:
    all_imgs[img] = pygame.image.load(img)

  1. Then looping through img_names, you can blit each image to the screen

for img in img_names:
    screen.blit(all_imgs[img], (desiredx, desiredy))
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76