python - 新行字符在 Pygame 窗口的格式化输出中不起作用

标签 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

看到零和“蛋”之间的方框了吗? 然后我用这个更新了代码:

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/

相关文章:

python - 如何在按键事件后将函数blit到屏幕(pygame)

python - Pygame 文本未绘制

python - 在我自己的 C 模块中使用 python 模块的 C API

python - pygame.init() 到底做了什么?

python - 两组标记之间的相似度得分

python - mplot3d:轮廓偏移、限制和刻度

python - Pygame 类型错误 : update() takes 1 positional argument but 2 were given

python - 通过与第二个列表比较从列表中删除项目,Python

python - 导入 mlxtend python 的问题

python - pygame - KEYDOWN 事件 - 行未更新位置