import pygame, sys #player class class Player(pygame.sprite.Sprite): def __init__(self, pos_x, pos_y): super().__init__() self.sprites = [] self.is_animating = False self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_1.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_2.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_3.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_4.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_5.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_6.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_7.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_8.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_9.png")) self.sprites.append(pygame.image.load("W:\\12\\noah.burrell\Programming\Practice\Pygame\\frog\\attack_10.png")) self.current_sprite = 0 self.image = self.sprites[self.current_sprite] self.rect = self.image.get_rect() self.rect.topleft = [pos_x, pos_y] def animate(self): self.is_animating = True def update(self): if self.is_animating == True: self.current_sprite += 0.15 if self.current_sprite >= len(self.sprites): self.current_sprite = 0 self.is_animating = False self.image = self.sprites[int(self.current_sprite)] #init pygame.init() clock = pygame.time.Clock() #screen screen_width = 150 screen_height = 100 screen = pygame.display.set_mode((screen_width,screen_height)) pygame.display.set_caption("Sprite Animation") # sprites and groups moving_sprites = pygame.sprite.Group() player = Player(10,30) moving_sprites.add(player) # gameloop while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: player.animate() screen.fill((0,0,0)) moving_sprites.draw(screen) moving_sprites.update() pygame.display.flip() clock.tick(60)