Pygame needs “for event in pygame.event.get()” in order not to crash

后端 未结 3 2141
失恋的感觉
失恋的感觉 2020-11-27 08:04

The program works fine like this but, I don\'t understand why it needs the useless for event in pygame.event.get(): None in the gameOver while stat

3条回答
  •  Happy的楠姐
    2020-11-27 08:30

    You can replace it with pygame.event.pump(). The documentation explains why you need to call this or have to use an event loop each frame.

    For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system. If you are not using other event functions in your game, you should call pygame.event.pump() to allow pygame to handle internal actions.

    This function is not necessary if your program is consistently processing events on the queue through the other pygame.eventpygame module for interacting with events and queues functions.

    There are important things that must be dealt with internally in the event queue. The main window may need to be repainted or respond to the system. If you fail to make a call to the event queue for too long, the system may decide your program has locked up.

提交回复
热议问题