Hello, i try to animate a character with 3 frames named "playerf1", 2 and 3, in a "player animation" folder.
I use pygame but that is not at the origin of the problem ^^.
So, i have this error :
self.image2 = self.images[self.current_image]
KeyError: 1
I found that this error occurs when the thing i want to find doesnt exist but right here i dont know why it can not find the images in the dictionnary...
Thanks for your help ^^
I use pygame but that is not at the origin of the problem ^^.
So, i have this error :
self.image2 = self.images[self.current_image]
KeyError: 1
I found that this error occurs when the thing i want to find doesnt exist but right here i dont know why it can not find the images in the dictionnary...
Thanks for your help ^^
class AnimateSprite(pygame.sprite.Sprite):
def __init__(self, sprite_name):
super().__init__()
#load the player
self.image2 = pygame.image.load(sprite_name + '.png')
self.current_image = 0
self.images = animations.get(sprite_name)
# animate the sprite
def animate(self):
self.current_image += 1
if self.current_image >= len(self.images):
self.current_image = 0
self.image2 = self.images[self.current_image]
def load_animation_images(sprite_name):
images = []
path = "player animation/" + sprite_name
for num in range(1, 3):
image_path = path + str(num) + '.png'
#pygame.image.load is used to load the image_path
images.append(pygame.image.load(image_path))
return images
animations = {
'player': load_animation_images('playerf')
}
