我在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
答案 0 :(得分:1)
每次要使用时,都必须渲染文本Surface:
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