Faster version of 'pygame.event.get()'. Why are events being missed and why are the events delayed?
Solution 1:
[...] and have two for event in
pygame.event.get()
loops [..]"
That's the issue. pygame.event.get()
get all the messages and remove them from the queue. See the documentation:
This will get all the messages and remove them from the queue. [...]
If pygame.event.get()
is called in multiple event loops, only one loop receives the events, but never all loops receive all events. As a result, some events appear to be missed.
Get the events once per frame and use them in multiple loops or pass the list or events to functions and methods where they are handled:
def handle_events(events):
for event in events:
# [...]
while run:
event_list = pygame.event.get()
# [...]
# 1st event loop
for event in event_list:
# [...]
# [...]
# 2nd event loop
for event in event_list:
# [...]
# [...]
# function which handles events
handle_events(event_list)