1

I can't figure out how to make it so that with one click of a button, not being held down, i can have an event that cycles through several images, each one lasting for several frames. Also to have it do that with the rest of the program running normally and not pausing for the images.

oregbelac
  • 13
  • 2

1 Answers1

2

Create a list of images:

image_list = [image1, image2, ...]

and an index which states the current image:

current_i = 0

Create a timer event (pygame.time.set_timer()) and increment the index when the event occurs:

image_timer = pygame.USEREVENT+1
pygame.time.set_timer(image_timer, 3000) # 3000 milliseconds == 3 seconds

run = True
while run:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False 
        if event.type == image_timer:
            current_i += 1
            if current_i == len(image_list):
                current_i = 0

Note, pygame.time.set_timer() repeatedly create an event on the event queue every given number of milliseconds.

Blit the image with index current_i:

window.blit(image_list[current_i], (0, 0))
Rabbid76
  • 202,892
  • 27
  • 131
  • 174