1. Load images only once.
Do not double call pygame.display.update.
Only do it once.
clock.tick belongs in game loop.
It must happen every frame.
remove global walkcount from redrawGameWindow().
Since image just repeat. Do something like.
napkin = [ pygame.image.load('napkin.png').convert_alpha(), pygame.image.load('napkin2.png').convert_alpha(), pygame.image.load('napkin3.png').convert_alpha()]2. Learn pygame.Rect. It has 2d math built into it.
class Player(object): def __init__(x, y, w, h): self.rect = pygame.Rect(x, y , w, h)
Do not double call pygame.display.update.
Only do it once.
clock.tick belongs in game loop.
It must happen every frame.
remove global walkcount from redrawGameWindow().
Since image just repeat. Do something like.
self.walk_right = [0, 1] self.walk_left = [0, 2] self.walk = 'idle' # in Player draw. if self.walk == 'idle': win.blit(napkin[0], self.rect) # (x, y) elif self.walk == 'right': win.blit(napkin[self.walk_count], self.rect) # (x, y) self.walk_count = (self.walk_count + 1) % len(self.walk_right) elif self.walk == 'left': win.blit(napkin[self.walk_count], self.rect) # (x, y) self.walk_count = (self.walk_count + 1) % len(self.walk_left)
99 percent of computer problems exists between chair and keyboard.