1

i'm making a plane shooter game. I have made different plane sprites and i'm looking for a way to animate them so that my plane looks like its turning its propeller infinitely. myPlane (in position 1)

pos1 = pygame.image.load(r'C:\Users\me\Documents\MyGame\planee.png')
pos2 = pygame.image.load(r'C:\Users\me\Documents\MyGame\planee2.png')
pos3 = pygame.image.load(r'C:\Users\me\Documents\MyGame\planee3.png')
pos4 = pygame.image.load(r'C:\Users\me\Documents\MyGame\planee4.png')
pos5 = pygame.image.load(r'C:\Users\me\Documents\MyGame\planee5.png')

So keep in mind that from the start of the game to its end, the plane should seem to be turning its propeller infinitely, it means that this is not related to pressing or key or any event. How could i do that ?

Developeeer
  • 110
  • 1
  • 1
  • 10

1 Answers1

1

Make a list of the images for animation:

image_list = [pos1, pos2, pos3, pos4, pos5]

Add a variable that will store an index of the image list:

current_image = 0

Increment the index in the application loop and reset the index if it is equal to the length of the list:

run = True
while run:
    # [...]

    current_image += 1
    if current_image == len(image_list):
        current_image = 0

    # [...]

Get the current image by subscription:

screen.blit(image_list[current_image], x, y)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174