pygame仅在特定功能或类似效果期间帧速慢?

2024-09-29 23:21:35 发布

您现在位置:Python中文网/ 问答频道 /正文

只有在运行特定功能时,才有办法降低程序的帧速率吗?我制作了一个类,它在屏幕上一次呈现一个字符的文本来模拟打字。正如预期的那样,每个角色都以帧速率的速度渲染,这不是我想要的效果。更改帧速率有帮助,但我不想影响我可能有的任何其他动画。有没有一种方法可以做到这一点,或者我没有想到的工作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)

Tags: textrectself程序速率defpygamesurf
1条回答
网友
1楼 · 发布于 2024-09-29 23:21:35

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

这是我关于堆栈溢出的第一个答案,我回答了这个问题,因为我已经实现了这样的事情

相关问题 更多 >

    热门问题