Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 显示游戏计时器_Python_Pygame - Fatal编程技术网

Python 显示游戏计时器

Python 显示游戏计时器,python,pygame,Python,Pygame,我在pygame中制作了一个游戏,其中包括一个计时器,当玩家死亡时计时器停止。但是,我在屏幕上显示计时器时遇到了一些问题,而不是在python shell中。希望你能帮助我:D pygame.time.get_ticks()/1000 font = pygame.font.SysFont("Times New Roman", 30) text = font.render("Time", True, color) running=True while running: event = p

我在pygame中制作了一个游戏,其中包括一个计时器,当玩家死亡时计时器停止。但是,我在屏幕上显示计时器时遇到了一些问题,而不是在python shell中。希望你能帮助我:D

pygame.time.get_ticks()/1000
font = pygame.font.SysFont("Times New Roman", 30)
text = font.render("Time", True, color)

running=True
while running:
    event = pygame.event.wait ()
    if pygame.sprite.colliede_rect(block, block1):
        window.blit(text, (window_width/2, window_height/2-100))
        pygame.display.update()
        print("du overlevede",pygame.time.get_ticks()/1000, "sekunder")  
        pygame.time.wait(5000)
        running = False

每次要使用文本表面时,都必须对其进行渲染:

pygame.time.get_ticks()/1000
font = pygame.font.SysFont("Times New Roman", 30)

running=True
while running:
    event = pygame.event.wait ()
    if pygame.sprite.colliede_rect(block, block1):
        time_string = "Time du overlevede {} sekunder".format(pygame.time.get_ticks()/1000)
        text = font.render(time_string, True, color)

        window.blit(text, (window_width/2, window_height/2-100))
        pygame.display.update()

        pygame.time.wait(5000)
        running = False

详细的错误信息是什么?请提供有关您的问题的更多信息。@user3601885没问题,欢迎使用StackOverflow。将来,您可能希望提供问题的更多细节,例如您正在运行的python、pygame和其他模块的版本,足够的代码自行运行并重现问题,特别是您的程序做什么与您希望它做什么,完整的错误回溯(如果适用)(不在此),总的来说,关于这个问题的信息要尽可能多。在本例中,我看到了代码中的问题,但它通常不是那么简单。