-1
\$\begingroup\$

What I'm doing

So I'm developing a game for my Computer Science final with python & pygame. It's done other then I have to make a main menu. I've been developing it over the last 2 weeks because it's been Winter break for me (I'm in high school if that matters) and I've been developing it on my home computer.

My home computer was running my game 60 FPS and never dropped lower than 55. Though I've just recently transferred it to my school laptop, the laptop I have to present it in and I'm getting 25-35FPS.

What I've done

I've converted everything that doesn't use transparency (.convert()), I enabled Fullscreen and I'm currently downloading Pypy to hopefully improve performance.

What I'm trying to do

Apparently in the Pygame performance thread there is a way to only update things that you need to update.

Though the thing is, for me in terms of graphics, everything needs to be updated but 2 things. Though these 2 things are what's dropping my FPS. The background image, and the block images.

What I'm asking for

Is there a way, certain line of code or command where I can exclude these things from being updated. Instead of having to have update only update everything but it.

Like a simpler or faster way. Can i write something like pygame.display.update(!background), something like that maybe?

\$\endgroup\$
0
\$\begingroup\$

I would try to utilize the sprite groups in pygame to hold only the objects you want to update. Then calling update() and draw() on that group will only update the sprites that you've added to it.

Also when looking at the groups it may be worth investigating the RenderUpdates group which is supposed to optimize its draw() method, but I haven't played around with it enough to see exactly how it works or how much it helps. Here is the documentation for this group: Render Update Doc

I would also recommend looking through the examples provided with the pygame library as I've found them very useful for understanding different parts of the functionality pygame supplies.

You mentioned that the background is one of the objects that is currently limiting your performance. If that is the case try looking at the aliens.py example (the example was inclueded in pygame-1.9.1-release/examples/aliens.py) to see an example of how the background can be separated out from the rest of the objects to help with performance.

First initialize the background

 # create the background, tile the bgd image
bgdtile = load_image('background.gif')
background = pygame.Surface(SCREENRECT.size)
for x in range(0, SCREENRECT.width, bgdtile.get_width()):
    background.blit(bgdtile, (x, 0))
screen.blit(background, (0, 0))
pygame.display.flip()

Utilize the background when clearing other sprites

 # clear/erase the last drawn sprites
 all.clear(screen, background) # all is a sprite group
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.