'Animated walking in Pygame stuck [duplicate]
I'm trying to make my code cycle through images every time I hit an arrow key to move it to make it appear like animated walking. However, the sprite is keeping the initial image as it moves around. Here I've included an example of the up movement.
class Player(pygame.sprite.Sprite):
def __init__(self):
super(Player, self).__init__()
self.surf = pygame.image.load("down1.png").convert()
self.surf.set_colorkey((255, 255, 255), RLEACCEL)
self.rect = self.surf.get_rect()
def update(self, pressed_keys):
up_counter = 0
down_counter = 0
right_counter = 0
left_counter = 0
if pressed_keys[K_UP]:
player = pygame.image.load(up_images[up_counter]).convert()
self.surf.set_colorkey((255, 255, 255), RLEACCEL)
up_counter = (up_counter + 1) % len(up)
self.rect.move_ip(0, -5)
down_counter = 0
left_counter = 0
right_counter = 0
Does anyone know how I could fix this? Please let me know if I'm missing any info that could be helpful in solving. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
