ValueError:rectstyle对象Pygam无效

2024-09-28 03:23:03 发布

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

试图在屏幕上显示分数。我是通过清除屏幕上显示分数的部分,然后在中添加新的分数来完成的。然而,当我尝试这样做时,我不断得到这个错误“ValueError:invalid rectstyle object”。有人知道怎么解决这个问题吗?你知道吗

以下是所有涉及的代码:

在主要功能中:

 screen.fill(WHITE,((1280/2),(720/2) - 250))
 displayText(scoreText,50,((1280/2),(720/2) - 250))

其他正在使用的功能:

def textObjects(text,font):
    textSurface = font.render('{}'.format(text),True,BLACK)
    return textSurface, textSurface.get_rect()

def displayText(text,fontSize = 100, center = ((1280/2),(720/2))):
    fontInfo = pygame.font.Font(None,fontSize)
    textSurf, textSize = textObjects(text,fontInfo)
    textSize.center = (center)
    screen.blit(textSurf,textSize)
    pygame.display.update()

Tags: text功能屏幕defscreenpygame分数center

热门问题