How to count for a certain amount of seconds before breaking from program
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 | 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 2 3 4 5 6 7 8 9 10 11 | 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() |