I recently saw a question on animation in pygame and in the answer, a code was given which works perfectly, by a user @Rabbid76 which is:
explosionList = []
while run:
current_time = pygame.time.get_ticks()
# [...]
for missile_idx, missile_val in enumerate(missiles)
# [...]
if missile_rect.colliderect(rock_rect):
explosion_sound.play()
explosion_pos_x = missile_pos_x
explosion_pos_y = missile_pos_y
end_time = current_time + 2000 # 2000 milliseconds = 2 seconds
explosionList.insert(0, (end_time, explosion_pos_x, explosion_pos_y))
# [...]
for i in range(len(explosionList)):
if current_time < explosionList[i][0]:
screen.blit(explosion, (explosionList[i][1], explosionList[i][2]))
else:
explosionList = explosionList[:i]
break
# [...]
This, as I mentioned, works well... thanks @Rabbid76 But can someone improve this code so that a list of 10 images can be displayed on the screen using the same format, with a 100-millisecond gap?? I tried to do it, but the images are printing spontaneously and stacked on each other...