I have an animation I need to play every time the mouse button is clicked.
I have the frames stored in a list, for every frame that Pygame renders, one frame in the list is blit
to the screen.
My issue is that because this happens every frame, the animation is played at 1000fps, even though there are only 8 frames, so the animation is unnoticeable. Is there any way to run the animation at 16fps while still allowing Pygame to run through the game loop at normal speeds? I have a game that needs to be run at Pygame's normal render speed but the animations should be played slower.
Here is an example of what I am currently doing:
pygame.init()
screen = pygame.display.set_mode((800, 600))
running = True
while running:
screen.fill('#000000')
mouse_pos = pygame.mouse.get_pos()
explosion = (pygame.image.load('assets/Explosion/E_1.png'), pygame.image.load('assets/Explosion/E_2.png'),
pygame.image.load('assets/Explosion/E_3.png'), pygame.image.load('assets/Explosion/E_4.png'),
pygame.image.load('assets/Explosion/E_5.png'), pygame.image.load('assets/Explosion/E_6.png'),
pygame.image.load('assets/Explosion/E_7.png'), pygame.image.load('assets/Explosion/E_8.png'))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
for frame in explosion:
framerect = frame.get_rect(center=mouse_pos)
screen.blit(frame, framerect)
pygame.display.update()
pygame.quit()