What is causing my game to have really low fps [closed]

I took a look at your code and found the solution in changing line 392 inside the __init__ method of your Map object from

self.currentmap = pygame.image.load(os.path.join("assets", "maps", "spawn.png"))


self.currentmap = pygame.image.load(os.path.join("assets", "maps", "spawn.png")).convert()

If you have images that don’t need an alpha channel you should always call convert on them.

At the beginning I had a framerate of 18 fps now it’s the desired 60 fps.

The key tool to find this bottleneck was the python module cProfile. Next time you should learn about it before posting a wall of nearly 500 lines of code .

Also consider changing the loading of your image files to the initialization of your objects into a list. Currently you are loading all the images for your characters each time you render them.

Leave a Comment