Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygame Sound/Font/Delay seems to be out of order

I'm making a Snake type game using Pygame. Everything's pretty much working, but below is the end of my game. There's a sound effect, and I put in the delay so the window didn't close before the sound finished playing. It all worked fine, and I just added in the Game Over text. For some reason, the sound plays, the game pauses, and then the Game Over quickly flashes on the screen. Can anyone explain to me why this is going out of order?

I'm using Python 2.7 on Mac 10.6.8.

if w.crashed or w.x<=0 or w.x >= width - 1 or w.y<=0 or w.y >= height -1:
    gameover.play()
    font = pygame.font.Font(None, 80)
    end_game = font.render("Game Over!", True, (255, 0, 0), (0,0,0))
    endRect = end_game.get_rect(centerx = width/2, centery = height / 2)
    screen.blit(end_game, endRect)
    pygame.time.delay(3500)
    running = False
like image 217
thumbtackthief Avatar asked Dec 07 '25 02:12

thumbtackthief


1 Answers

Could it be that you are missing pygame.display.flip() or display.update(rectangle=endRect) right after the screen.blit() call ?

like image 122
mjv Avatar answered Dec 08 '25 15:12

mjv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!