只有在运行特定功能时,才有办法降低程序的帧速率吗?我制作了一个类,它在屏幕上一次呈现一个字符的文本来模拟打字。正如预期的那样,每个角色都以帧速率的速度渲染,这不是我想要的效果。更改帧速率有帮助,但我不想影响我可能有的任何其他动画。有没有一种方法可以做到这一点,或者我没有想到的工作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,然后重复整个过程,直到所有文本都打印出来这是我关于堆栈溢出的第一个答案,我回答了这个问题,因为我已经实现了这样的事情
相关问题 更多 >
编程相关推荐