Python 如何实时更新pygame中的时间
我试图实时显示游戏已经运行了多长时间。为此,我使用了Python 如何实时更新pygame中的时间,python,pygame,Python,Pygame,我试图实时显示游戏已经运行了多长时间。为此,我使用了self.time\u passed=pygame.time.get\u ticks()/1000并将其命名为g.write(“时间:%d”%(g.time\u passed),g.white,10,10,50)。我的写入函数如下所示: def write(self, text, color, x , y, size): font = pygame.font.SysFont("airel", size)
self.time\u passed=pygame.time.get\u ticks()/1000
并将其命名为g.write(“时间:%d”%(g.time\u passed),g.white,10,10,50)
。我的写入函数如下所示:
def write(self, text, color, x , y, size):
font = pygame.font.SysFont("airel", size)
text = font.render(text, True, color)
textRect = text.get_rect()
self.screen.blit(text,(x , y))
import pygame
pygame.init()
font18 = pygame.font.SysFont("ariel", 18)
displaysurf = pygame.display.init((1280, 720))
def write(f, t, x, y, c):
textsurf = f.render(t, True, c)
displaysurf.blit(textsurf, (x, y)
我的问题是时间没有实时更新。它只会更新玩家每次死亡的秒数,即使我将
g.write(“时间:%d”%(g.Time_passed),g.white,10,10,50)
放在我的主中,而True:
游戏循环。谢谢您的帮助。我想这是因为系统字体名为Arial
,而不是airel
。或者您正在使用字体天线
这可能会导致此函数失败,并且在玩家死亡时调用的函数工作正常。我猜这是因为系统字体名为
Arial
,而不是airel
。或者您正在使用字体天线
这可能会导致此函数失败,并且在玩家死亡时调用的函数工作正常。我个人会使用time.time() 另外,您可能只需要像下面这样声明一次字体:
def write(self, text, color, x , y, size):
font = pygame.font.SysFont("airel", size)
text = font.render(text, True, color)
textRect = text.get_rect()
self.screen.blit(text,(x , y))
import pygame
pygame.init()
font18 = pygame.font.SysFont("ariel", 18)
displaysurf = pygame.display.init((1280, 720))
def write(f, t, x, y, c):
textsurf = f.render(t, True, c)
displaysurf.blit(textsurf, (x, y)
就我个人而言,我会利用时间 另外,您可能只需要像下面这样声明一次字体:
def write(self, text, color, x , y, size):
font = pygame.font.SysFont("airel", size)
text = font.render(text, True, color)
textRect = text.get_rect()
self.screen.blit(text,(x , y))
import pygame
pygame.init()
font18 = pygame.font.SysFont("ariel", 18)
displaysurf = pygame.display.init((1280, 720))
def write(f, t, x, y, c):
textsurf = f.render(t, True, c)
displaysurf.blit(textsurf, (x, y)
“它只会更新玩家每次死亡的秒数”-那么你做错了什么。“即使我将[…]放置在我的主中,而为True
”-您也必须显示代码,您可以在其中调用write
!write
功能与此问题完全无关。“它只会在玩家每次死亡时更新秒数”-那么你做错了什么。“即使我将[…]放置在我的主中,而为True
”-您也必须显示代码,您可以在其中调用write
!write
功能与此问题完全无关。