1

Can you help me? It's the first time that I use pygame and I found an error loading image. I've just searched in this site for a possible solution, but nothing seems to work for me. I tried to use pygame.image.load() with all the path or with a part, but it didn't work. I created this function that is similar of a function in pygame tutorial in the documentation of pygame.

def load_png(name = ""):
        current_path = os.path.dirname(__file__)
        game_path = os.path.join(current_path, 'game')
        image_path = os.path.join(game_path, 'images')
        image_path += "\\" + name
        image = pygame.image.load(image_path)
        if image.get_alpha() is None:
            image = image.convert()
        else:
            image = image.convert_alpha()
        return image, image.get_rect()

1 Answers1

0

The problem was an incorrect file name: "person1.png" instead of "person1.jpg".

If anyone has the same problem, try to print the files in the directory and compare them with the file names in your module.

How do I list all files of a directory?

skrx
  • 19,980
  • 5
  • 34
  • 48