Here's a question from a total newbie
I'm trying to write an evolution simulator. (Requirement) That implies having a lot of objects that are supposed to interact with one another. I'm writing the code in Python (since it's the only language that I know), using Pygame to create a visual 2D environment. I was doing fine until I added the trees to my continent. That's when things got super slow, since there're thousands of trees on screen that have to be there each frame.
I got rid of pygame.display.flip()
in favor of pygame.display.update()
. Doing that I've run into two
problems:
The
pg.draw.circle()
function leaves behind a trace when moved. I've run into problems with this function before (the rect created by the function can never leave the screen, apparently), but maybe it's just me who does something wrong?The optimization solution I've come up with so far is still dubious at best. If you delete line 32 in
bug.py
you'll see how much faster things run in the project. Is there a way to get my code running as fast as this, or at least close to that? I mean, I'm to add a hundred or more other bugs, all eating plants and other bugs, seeing stuff and thinking with their neural network each, the whole thing is gonna be a mess unless I optimize the code.
Thanks you all for your input!
EDIT: I feel like relying on the order of objects in the biomes
list instead of looping through every biome there is in bug.update_biomes()
would significantly increase the process speed, but what do you think?
P.P.S.: Also, I just found out that the pygame.Surface.fill()
function does not require and update. Where can I read which function in pygame require updates and which don't?