在pygame慢帧只有在一个特定的功能或类似的效果?



是否有一种方法可以降低我的程序的帧率,只有当一个特定的功能正在运行?我制作了一个类,每次在屏幕上呈现一个字符来模拟打字。正如预期的那样,每个角色都以帧率的速度渲染,这不是我想要的效果。改变帧率会有所帮助,但我不想影响我可能拥有的任何其他动画。有什么方法可以做到这一点或者我没有想到的方法吗?pygame.wait挂起整个程序。

# simulate printing text one character at a time on the screen
class TextPrint:
def __init__(self, xpos, ypos, fontSize, fontColor, string, gameSurface):
self.xpos = xpos
self.ypos = ypos
self.font = pygame.font.SysFont('Lucida Console', fontSize)
self.fontColor = fontColor
self.displayText = string
self.active = False # is the text area currently in use
self.activeIndex = 0 # index that is being added to current render
self.gameSurface = gameSurface

def update(self):
self.surf = self.font.render(self.displayText[:self.activeIndex], True, self.fontColor)
self.rect = self.surf.get_rect(x=self.xpos,y=self.ypos)
if self.activeIndex > len(self.displayText): pass
else: self.activeIndex += 1
def draw(self):
self.gameSurface.blit(self.surf, self.rect)

也许你可以尝试的是,有一个像count = 50这样的变量,然后在游戏循环中调用一个函数,将count的值减少1,然后当count的值为0时,然后你可以输入一个字符,然后将count重置为50,然后重复整个过程,直到你的所有文本都打印出来。

这是我对堆栈溢出的第一个回答,我回答这个是因为我已经实现了这样的事情。

最新更新