PyGame bogging down linux?

2020-05-03 12:18发布

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.

2条回答
叼着烟拽天下
2楼-- · 2020-05-03 12:30

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)
查看更多
We Are One
3楼-- · 2020-05-03 12:34

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.

查看更多
登录 后发表回答