Matt Clifford
Matt Clifford

Reputation: 9

How do I slow down a very simple animation in pygame

I need to slow down the animation so it is not at lighting speed. How would I do this??

here is a section of my code...

animation_counter = 0

player_animation_left = ["player_sprites/player_left.png","player_sprites/player_left1.png", "player_sprites/player_left2.png",]

 if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_LEFT:
            player_surf = pygame.image.load(player_animation_left[animation_counter])
            player_surf = pygame.transform.rotozoom(player_surf, 0, 2.5)
            animation_counter = (animation_counter + 1) % len(player_animation_left)
            player_rect.x -= 4

I was expecting to see it switch between each image more slowly.

Upvotes: 0

Views: 64

Answers (2)

Ben Moreau
Ben Moreau

Reputation: 29

From the pygame.time documentation, you can use pygame.time.delay() or pygame.time.wait() to stop the process for a few milliseconds.

Upvotes: 1

kevin
kevin

Reputation: 21

I'm not too familiar with pygame but instead of relying on a timer you can play the same frame of the animation for multiple frames of your game by using integer divison. i.e.:

animation_counter = n//10
n = (n+1) % len(player_animation_left)*10

This would make each animation frame last 10x longer.

Upvotes: 0

Related Questions