import pygame, sys class Player(pygame.sprite.Sprite): def __init__(self, pos_x, pos_y): super().__init__() self.sprites = [] self.is_animating = False self.sprites.append(pygame.transform.scale(pygame.image.load('attack_1.png'), (1000, 1000))) # Resize the image here # Add the rest of your images with scaling if needed 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,speed): if self.is_animating == True: self.current_sprite += speed if self.current_sprite >= len(self.sprites): self.current_sprite = 0 self.is_animating = False self.image = self.sprites[int(self.current_sprite)] # General Setup pygame.init() clock = pygame.time.Clock() # Game Screen screen_width = 1920 screen_height = 1080 screen = pygame.display.set_mode((screen_width,screen_height)) pygame.display.set_caption("Sprite Animation") # Creating sprites and groups moving_sprites = pygame.sprite.Group() player = Player(10,10) moving_sprites.add(player) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: player.animate() # Drawing screen.fill((0,0,0)) moving_sprites.draw(screen) moving_sprites.update(0.2) pygame.display.flip() clock.tick(60)