在打破程序之前如何计算一定的秒数

时间:2014-02-01 16:20:58

标签: python time pygame

if pygame.sprite.collide_rect(ship,missile) == True:
    ship.image = pygame.image.load("lose.jpg")
    ship.image = ship.image.convert()
    ship.rect = ship.image.get_rect()
    break

我如何制作它以便在显示'lose.jpg'然后中断并退出程序时等待几秒钟?

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

def pause(time_to_wait):
    clock = pygame.time.Clock()
    total = 0
    while True:
    total += clock.tick()
    if(total > time_to_wait):
        return
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()