for i, line in enumerate(img_text):
text_surf = font.render(line, True, (255, 255, 0))
window.blit(text_surf, (50, 20 + i * text_height))
使用以下功能:
def renderTextImage(surf, font, text, x, y, color):
img_text = text.splitlines()
for i, line in enumerate(img_text):
text_surf = font.render(line, True, color)
surf.blit(text_surf, (x, y + i * text_height))
好的,那么基本上,您想要打印一个带有文本的ASCII图像。这应该不会太难
首先,将ASCII图像设置为变量。例如:
接下来,将要打印的文本设置为另一个变量
最后,按如下方式打印两个:
或:
\n
只是指一个新行要执行与使用Pygame的SanctuaryRPG相同的操作,您需要使用每个字符宽度相同的字体(例如Courier):
用
splitlines()
将文本拆分为几行(请参见How to split a python string on new line characters):在循环中逐行渲染文本:
使用以下功能:
最简单的例子:
repl.it/@Rabbid76/PyGame-AsciiTextImage
相关问题 更多 >
编程相关推荐