Я работаю над тем, чтобы текст отображался в моем pygame, который я создаю. Я нарисовал его с приятным пространством между текстом, но с переводом слова текст перекрывается чуть-чуть. Вот как я обматываю свой текст.Pygame word wrap
def reOrderChat(nText, nColor):
''' Reorders the chat text on screen and creates new lines '''
# rearrange the lines first so they stay correct.
for c in range(19, 0, -1):
DrawnChat[c + 1].text = DrawnChat[c].text
DrawnChat[c + 1].color = DrawnChat[c].color
DrawnChat[c + 1].y = DrawnChat[c].y - 8
#print "Text at " + str(c + 1) + " is " + DrawnChat[c + 1].text
# check if textlength is greater than the chat list length
textLength = g.chatFont.size(nText)[0]
if textLength > 459:
# todo: allow custom size chat list (459 is found with GIMP)
# todo: optimize the loop
lines = ['']
words = nText.split()
curLine = 0
curLineLength = 0
for i in range(len(words)):
word = words[i]
# if adding the new word to the current line would be too long,
# then put it on a new line
wordLength = g.chatFont.size(word)[0]
if (curLineLength + wordLength) > 400: # todo: why does it only work with 400?
# only move down to a new line if we have text on the current line
lines.append('')
curLine += 1
curLineLength = 0
lines[curLine] += word + ' '
curLineLength += wordLength
curLine +=1
for line in lines:
print line
print str(curLine)
# here is where it creates new chat lines. This is where the issue is.
DrawnChat[curLine].text = line
DrawnChat[curLine].color = nColor
DrawnChat[curLine].y += 8
curLine -= 1
else:
# text fits, so just print it
# lastly add the new text and color at position 1
DrawnChat[1].text = nText
DrawnChat[1].color = nColor
DrawnChat[1].y += 8
Вот скриншот из текста. Между двумя первыми линиями недостаточно места. Через интервал после первых двух строк в MOTD: это просто отлично. Я устанавливаю значение y неправильным, если существует несколько строк?
Действительно ли пространство для MOTD нормально? или он просто выглядит нормально из-за пустой строки перед этим? Вы пытались увеличить значение y? – elParaguayo