I have a few files, following a video tutorial on how to make a platformer in PyGame. I keep getting the error pygame.error: Unsupported image format
, but this only happens every now and then. Probably 5% of the time, the image files will load as the player, and the other 95% of the time, if I recreate the directory a few times, it might work.
This is the full error message:
Traceback (most recent call last): File "/Users/Serena/PycharmProjects/GApp/code/main.py", line 73, in <module> game.run() File "/Users/Serena/PycharmProjects/GApp/code/main.py", line 54, in run self.overworld.run() File "/Users/Serena/PycharmProjects/GApp/code/overworld.py", line 118, in run self.input() File "/Users/Serena/PycharmProjects/GApp/code/overworld.py", line 97, in input self.create_level(self.current_level) File "/Users/Serena/PycharmProjects/GApp/code/main.py", line 32, in create_level self.level = Level(current_level,screen,self.create_overworld,self.change_health) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/Serena/PycharmProjects/GApp/code/level.py", line 28, in __init__ self.player_setup(player_layout,change_health) File "/Users/Serena/PycharmProjects/GApp/code/level.py", line 165, in player_setup sprite = Player((x,y),self.display_surface,self.create_jump_particles,change_health) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/Serena/PycharmProjects/GApp/code/player.py", line 8, in __init__ self.import_character_assets() File "/Users/Serena/PycharmProjects/GApp/code/player.py", line 47, in import_character_assets self.animations[animation] = import_folder(full_path) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/Serena/PycharmProjects/GApp/code/support.py", line 13, in import_folder image_surf = pygame.image.load(full_path).convert_alpha() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^pygame.error: Unsupported image format
Here is the code for the import_folder()
function and the import_character_assets()
function.
def import_folder(path): surface_list = [] for _, __, image_files in walk(path): for image in image_files: full_path = path +'/'+ image image_surf = pygame.image.load(full_path).convert_alpha() surface_list.append(image_surf) return surface_list
def import_character_assets(self): character_path = '/Users/Serena/PycharmProjects/GApp/graphics/character/' self.animations = {'idle':[],'run':[],'jump':[],'fall':[]} for animation in self.animations.keys(): full_path = character_path + animation self.animations[animation] = import_folder(full_path)
However, it loads one image (not animated) in the overworld.py file using this function:
class Icon(pygame.sprite.Sprite): def __init__(self,pos): super().__init__() self.pos = pos self.image = pygame.image.load('/Users/Serena/PycharmProjects/GApp/graphics/character/idle/1.png').convert_alpha() self.rect = self.image.get_rect(center = pos)
Also, the image files are all 64x64, and are in the correct directory. I've tried using the absolute file path, relative path, and path.join(), but it doesn't seem to make a difference. Any ideas? Thank you in advance!