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

后端 未结 3 2153
失恋的感觉
失恋的感觉 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条回答
  •  长情又很酷
    2020-11-27 08:48

    Every process with a GUI needs to maintain a Message Pump (at least in Windows it's critical)

    Most of the time, your GUI framework (QT for example) will maintain the pump for you - and will dispatch matching events for your callbacks (mouse clicks, keyboard etc..).

    I guess that pygame wants to give you some finer control about how you handle the messages (if I'm not mistaken, game engines would want to wait and pump all events with each rendering of a single frame).

提交回复
热议问题