Pygame窗口中的新行字符无法在格式化输出中使用

时间:2016-11-01 13:49:40

标签: python pygame

我在Pygame窗口中打印格式化的文本。除了我想要放在两个值之间的换行符('\n')之外,全文正确打印。新系列作为一个盒子出现,就像在非UNICODE区域打印UNICODE字符一样。 无论如何,看看:

def updateScoreBoard():
     font=pygame.font.SysFont(None,14)
     text=font.render('Score: %05d \n Egg Caught: %03d' %(SCORE,EGGSCAUGHT),True,pygame.Color(255,255,255))
     textRect=text.get_rect()
     mainSurface.blit(text,textRect)

我得到的结果是enter image description here

请参阅零和' Egg之间的框? 然后我用这个更新了代码:

NEWLINE='\n'
def updateScoreBoard():
     font=pygame.font.SysFont(None,14)
     text=font.render('Score: %05d %s Egg Caught: %03d' %(SCORE,NEWLINE,EGGSCAUGHT),True,pygame.Color(255,255,255))
     textRect=text.get_rect()
     mainSurface.blit(text,textRect)

仍然是相同的结果。我现在做什么?

2 个答案:

答案 0 :(得分:1)

PyGame doc:Font.render()

  

文本只能是一行:不呈现换行符。

答案 1 :(得分:0)

可能的解决方案如下:

{{1}}