How would I execute some code after a set number of milliseconds?
I only want to execute it once.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s the
pygame.time.set_timer(eventid, milliseconds)function, which generates an event with ideventidon the event queue everymillisecondsmilliseconds, which you can then handle however you like. You can stop the event from being generated again by callingpygame.time.set_timer(eventid, 0).SDL has an
SDL_AddTimerfunction that does exactly what you want — you pass it a callback function to be executed after some delay, but from the documentation I can’t really find thepygameequivalent.For a python solution, you can use the
threading.Timerclass.