Я работаю над проектом и визуализирую текст для отображения в окне, но текст не умещается на экране при отображении в одну строку, поэтому я написал сценарий для добавления символа новой строки всякий раз, когда текст выскакивает за пределы экрана, и он работает.
Код: Выделить всё
def display_text_animation(string,x,y):
text = ''
next_width = 0
for i in range(len(string)):
text += string[i]
if string[i] == ' ' and next_width == 0:
pass
try:
if string[i] == ' ' and i < len(string):
next_width = textSur_font.render(text + string[i + 1:string.find(" ", i + 1) if string.find(" ", i + 1) != -1 else len(string)], True, "#FFFFFF").get_width()
except:
pass
if (next_width >= SCREEN_WIDTH +100 ):
text += "\n"
next_width = 0
if text[-1] == "\n":
next_width = 0
text_surface = desc_font.render(text, True, "#FFFFFF", backGroundCol)
text_rect = text_surface.get_rect()
text_rect.x = x
text_rect.y = y
screen.blit(text_surface, text_rect)
pygame.display.update()
pygame.time.wait(40)

But I just noticed in the documentation that it's not suppose to work.
And when I change the environment, it does not work and render everything in a single line.
someone knows what's going on?
I'm running on:
windows 11
python 3.11.5
pygame-ce 2.4.1
Источник: https://stackoverflow.com/questions/781 ... d-behavior