I'm making an application in pygame and I need to process events. I never really understood whether I should use pygame.event.get()
or pygame.event.poll()
, or if it really matters.
Question: Should I use pygame.event.get()
or pygame.event.poll()
?
for event in pygame. event. get() handles the internal events an retrieves a list of external events (the events are removed from the internal event queue). If you press the close button of the window, than the causes the QUIT event and you'll get the event by for event in pygame.
Pygame handles all its event messaging through an event queue. The routines in this module help you manage that event queue. The input queue is heavily dependent on the pygame. display pygame module to control the display window and screen module.
The function pygame. event. pump() is the function that put all events into the event queue (it doesn't clear the previous events, it just adds). The event queue won't be filled/updated with any events if the function isn't called.
get()
retrieves all events currently in the queue, and is usually used in a loop:
for event in pygame.event.get():
# use event
poll()
retrieves only a single event:
event = pygame.event.poll()
# use event
In the latter, you will need to explicitly check whether the type of event is a pygame.NOEVENT
; in the former, the loop simply won't run if there are no events.
Generally, it is more common to use the get()
version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With