Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use pygame.event.get() or pygame.event.poll()?

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()?

like image 877
Alexandre Pinho Avatar asked Feb 16 '14 12:02

Alexandre Pinho


People also ask

What does for event in Pygame event get () do?

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.

How do events work 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.

What does Pygame event pump do?

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.


1 Answers

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.

like image 146
jonrsharpe Avatar answered Sep 19 '22 18:09

jonrsharpe