I am working on a pygame and I would like the controlled character to flip between two images whenever it is moving to simulate walking. I've been working on a solution for a few hours now and can not think of anything. Here's some code I have tried.
'''Update the visual screen.'''
screen.fill(settings.bg_color)
player.blitme()
player_imagea = pygame.image.load('images/player_imagea.bmp')
player_imageb = pygame.image.load('images/player_imageb.bmp')
if player.moving_right and player.image == player_imagea:
player.image = pygame.image.load('images/player_imageb.bmp')
elif player.moving_right and player.image == player_imageb:
player.image = pygame.image.load('images/player_imagea.bmp')
#Draw the most recent screen
pygame.display.flip()
Doing this results in nothing happening aside from the movement I have already programmed. I have been able to get the image to switch upon the first keypress but nothing beyond that.