I am beginner and learning about pygame. I am following a tutorial to a simple game and I can not figure out what the problem is. I have a crash function and use a time.sleep(). But the time sleep occurs earlier making whole code kind of useless.
I am working on Mac but I do not think that should be causing this.
I have tried to put time.sleep() into another function and use that one in the crash function but that does not work as well and I am not sure if time.sleep have some kind of preference.
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def message_display(text):
largeText = pygame.font.Font('freesansbold.ttf',115)
TextSurf, TextRect = text_objects(text, largeText)
TextRect.center = ((display_width/2),(display_height/2))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
time.sleep(2)
game_loop()
def crash():
message_display('You Crashed')
The first two function should not be the problem but I posted them just to be sure. So when the car in game crashes, it is supposed to write big "You Crashed", then wait 2 seconds and restart the game with game_loop() function. But it stops the game, waits 2 seconds, then writes "You Crashed" and immediately restart the game.