Search code examples
pythontimepygamedelaywait

How to make a splash screen image stay on screen for 5 seconds in Pygame?


I have a simple Pygame game which I need to create a splash screen for that displays the game name for 5 seconds. This is currently being achieved by blitting some standard text to the display surface and calling pygame.time.delay(5000). However, whilst the 5 seconds elapse my game does not seem to be capturing any events. The event procedure is located in a while True: loop below the splash screen function but it is obvious that pygame.time.delay() is freezing my entire code... but I need the event procedure to still function so I can detect quit /escape key (to skip the splash screen) events.

Thanks in advance, Ilmiont


Solution

  • With Pygame you can use the pygame.time.get_ticks function when the splash screen appears and record this time. Continue getting input from the user and calling get_ticks to see if 5000 milliseconds have elapsed and when it has you may discontinue the splash screen and continue as normal.