【发布时间】:2014-05-25 18:18:45
【问题描述】:
试图写一个 pygame 程序,但我似乎无法弄清楚如何让 pygame 将文本格式化为没有第三方模块的段落。例如,我想要:
"Hello World, how are you doing today? I'm fine actually, thank you."
更接近于:
"Hello World, how are
you doing today? I'm
fine actually, thank you."
这是我的代码:
def instructions(text):
pressKey, pressRect = makeText('Last Block is a survival game. Every ten lines that you clear will shorten the screen, clear as many lines as possible before you run out of space!', smallFont, bgColor)
pressRect.center = (int(windowWidth/ 2), int(windowHeight / 2) + 100)
displaySurf.blit(pressKey, pressRect)
while press() == None:
pygame.display.update()
和makeText 函数:
def makeText(text, font, color):
surf = font.render(text, True, color)
return surf, surf.get_rect()
这样 pygame 可以将一长串文本分成 x 个单词的部分,并将其格式化为看起来有点像一个段落。现在,我正在使用大量的表面对象和 blits 让它看起来像这样,这看起来很乏味。还有什么方法可以达到效果?
【问题讨论】:
-
“外部模块”是指第三方模块还是不是
pygame的每个模块?换句话说,您可以使用内置模块吗?因为,如果是这样,您可能会对内置的textwrap模块感兴趣。 -
第 3 方 = 外面。如果可能,您能快速解释一下
textwrap模块吗?