PyGame bogging down linux?

2020-05-03 12:10发布

问题:

When I run my pygame code it bogs down the system. PyGame becomes unresponsive and it slows down Ubuntu so much that I've had to force a shut down twice.

I posted a very similar question here: Why is my basic PyGame module so slow?

but I decided to rephrase it because when I asked the original question I wasn't aware of the full symptoms.

回答1:

You should limit the fps, you can use clock.tick for that

while true:
    for event in pygame.event.get():
        #manage your events
    #update your sprites
    screen.blit(...) #draw to screen
    pygame.display.flip()
    clock.tick(30)


回答2:

If you decide to use a delay like suggested in the answer you accepted, you probably want to limit your FPS rather than just impose a constant delay. Doing so would ensure that your game runs at the same speed on both slow and fast machines, and doesn't delay itself needlessly during CPU intensive moments of game play. You'd also want to apply your delta time to any physics/movement calculations.