Pygame中的延迟功能

时间:2014-07-10 18:51:36

标签: python 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 个答案:

答案 0 :(得分: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)
相关问题