I want to be able to check for a user defined event in pygame pygame.USERVENT+1
to be specific. I have my main loop where a window is filled and things are drawn to the window. I also have a for loop to check for events such as quitting or resizing the window. Then I have a function that I call called draw_cursor()
. I am trying to check for the specific event of pygame.USEREVENT+1
in this function so I could use it to draw an object however I cannot seem to get this event without using the event queue in the main function to check if pygame.USERVENT+1
is in the event queue.
import pygame
pygame.init()
width, height = 1024, 648
window = pygame.display.set_mode((width, height), pygame.RESIZABLE)
pygame.time.set_timer(pygame.USEREVENT, 1000)
def display_cursor():
if pygame.event.poll().type == pygame.USEREVENT+1:
print("This should print when USERVENT is in the event queue")
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.VIDEORESIZE:
width, height = event.w, event.h
window = pygame.display.set_mode((event.w, event.h), pygame.VIDEORESIZE)
"""if event.type == pygame.USEREVENT+1:
print("This will print when USEREVENT in the event queue")"""
display_cursor()
window.fill((0,0,255))
pygame.display.flip()
The commented out part is the part that would actually print when pygame.USERVENT+1
is in the event queue. I use pygame.event.poll().type
as this returns the events as a number and pygame.USERVENT+1 is number 24. I would think this would work as pyame.event.poll().type
should return the number 24 when pygame.USEREVENT+1
is in the event queue. I also had a look at: https://www.pygame.org/docs/ref/event.html#pygame.event.peek to also check in a similar way if the event is in the event queue. I tried if pygame.event.peek(pygame.USEREVENT+1):
instead of if pygame.event.poll().type == pygame.USEREVENT+1:
It still didn't print out what I wanted it to do.
I would like to be able to check the specific event pygame.USERVEENT+1
only in this display_cursor()
function and I am not using pygame.event.get()
in a for loop just to check for one event as I have found it to slow down my program to a point where the window is barely responsive. Is there a way that I could only check for user defined events in a separate function without having to pass the event object to this function to stop it from slowing down? Is there also a parameter or similar function that I am missing that does exactly what I thought pygame.event.poll()
or pygame.event.peek()
did?