Pygame中的延迟函数
我正在开发一个简单的游戏,玩家得分,当他/她得分达到一定数量时,程序会在屏幕上打印一条消息并退出。我想让程序延迟一下,这样用户可以在程序关闭之前阅读这条消息。我试过使用pygame.time.delay,但它的效果是先延迟一会儿,然后立即打印消息,并且在同一时刻退出程序。我该如何先显示消息,延迟一下,然后再关闭游戏呢?
我的代码:
if player.points == 10:
pygame.time.delay(2500)
pygame.draw.rect(screen, white,[30,500,500,90])
won_message = font.render("You have won, congratulations!!!", True, black)
screen.blit(won_message, [150, 535])
1 个回答
2
在延迟之前,试着使用 pygame.display.flip
来强制更新屏幕:
if player.points == 10:
pygame.draw.rect(screen, white,[30,500,500,90])
won_message = font.render("You have won, congratulations!!!", True, black)
screen.blit(won_message, [150, 535])
screen.flip() # if screen is your display
pygame.time.delay(2500)