Rendering text with multiple lines in pygame

后端 未结 9 1586
日久生厌
日久生厌 2020-11-29 12:15

I am trying to make a game and I am trying to render a lot of text. When the text renders, the rest of the text goes off the screen. Is there any easy way to make the text g

9条回答
  •  一向
    一向 (楼主)
    2020-11-29 12:38

    Created this function that could help a bit :) Just make sure that each new paragraph is a new item on the list you are calling on this function.

    def multilineText(Surface, textAsList: list, font: str, size: int, colour, antialias: bool, centerTupleCoord: tuple, spaceBetweenLines: int):
        xPosition = centerTupleCoord[0]
        yPosition = centerTupleCoord[1]
        for paragraph in textAsList:
            fontObjsrt = pygame.font.SysFont(font, size)
            TextSurf = fontObjsrt.render(paragraph, antialias, colour)
            TextRect = TextSurf.get_rect()
            TextRect.center = (xPosition, yPosition)
            Surface.blit(TextSurf, TextRect)
            yPosition += spaceBetweenLines
    

提交回复
热议问题