如何创建一个在特定时间启动并且不会在 pygame 中中断我的程序的计时器?

How can I create a timer that will start at a certain time and wont interupt my program in pygame?

我正在制作这款游戏​​,您可以使用 w、a、s、d 键移动球。我正在尝试制作一个在您按下 "start game" 时启动的计时器。问题是,当我做类似 time.sleep 的事情时,它会中断球的运动。我想在屏幕的右上角渲染计时器并将其设置为 1 分钟(我还会为计时器停止的时间做一个条件语句,所以我希望这是可能的)。

我认为这是最简单的,并且最适合您的需求。

clock = pygame.time.Clock()
fps = 60  # Or whatever frame-rate you want to cap the game at.
time = 0
game_started = False

# This is the main loop.
while True:

    dt = clock.tick(fps)

    if game_started:
        time += dt
    if time >= 60000:  # 60 seconds.
        game_started = False

    # Then handle, events, update/draw objects etc.

只需在按下按钮时设置 game_started = Truetime 变量将随时间开始递增。然后,您可以随意将 time 变量绘制到屏幕上。如果你不想在它不是 运行 时绘制它,那么只需在 game_started 为 True 时将其 blit。