Advanced game made in pygame is too slow

Question:

I’ve been working on a game for a month and it’s quite awesome. I’m not very new to game developing.

There are no sprites and no images, only primitive drawn circles and rectangles.
Everything works well except that the FPS gets slow the more I work on it, and every now and then the computer starts accelerating and heating up.

My steps every frame (besides input handling):

  • updating every object state (physics, collision, etc), around 50 objects some more complex than the other
  • drawing the world, every pixel on (1024,512) map.
  • drawing every object, only pygame.draw.circle or similar functions

There is some text drawing but font.render is used once and all the text surfaces are cached.

Is there any information on how to increase the speed of the game?
Is it mainly complexity or is there something wrong with the way I’m doing it? There are far more complex games (not in pygame) that I play with ease and high FPS on my computer.
Should I move to different module like pyglet or openGL?

EDIT: thank you all for the quick response. and sorry for the low information. I have tried so many things but in my clumsiness I heavent tried to solve the “draw every pixel every single frame proccess” I changed that to be drawn for changes only and now it runs so fast I have to change parameters in order to make it reasonably slow again. thank you 🙂

Asked By: simon lav

||

Answers:

Without looking at the code its hard to say something helpful.
Its possible that you got unnecessary loops/checks when updating objects.

Have you tried increasing/decreasing the amount of objects?

How does the performance change when you do that?

Have you tried playing other games made with pygame?

Is your pc just bad?

I dont think that pygame should have a problem with 50 simple shapes. I got some badly optimized games with 300+ objects and 60+ fps (with physics(collision, gravity, etc.)) so i think pygame can easily handle 50 simple shapes. You should probably post a code example of how you iterate your objects and what your objects look like.

Answered By: xSparfuchs
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.