我正在 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)
看到零和“蛋”之间的方框了吗? 然后我用这个更新了代码:
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)
结果还是一样。我现在做什么?
最佳答案
PyGame 文档:Font.render()
The text can only be a single line: newline characters are not rendered.
关于python - 新行字符在 Pygame 窗口的格式化输出中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40361414/