pygame.font.Font与pygame.freetype.Font有何不同?

时间:2018-10-05 13:37:46

标签: fonts pygame

要执行自动换行,我必须使用pygame.freetype.Font。但是,pygame.font.Font的输出与pygame display的输出不同。这是我的换行代码。

Afont = pygame.font.Font("fonts.ttf", 26)
Bfont = pygame.freetype.Font("fonts.ttf", 26)

def edit_text(text, font, x1, y1):
     font.origin = True
     words = text.split("")
     width, height = display.get_size() #display = pygame.display.set_mode((1000, 500))
     line_spacing = font.get_sized_height() + 2
     x, y = x1, y1+line_spacing

     space = font.get_rect("")
     for word in words:
        bounds = font.get_rect(word)
        if x + bounds.width + bounds.x+17 >= width:
            x, y = x1, y + line_spacing
        if x + bounds.width + bounds.x+17 >= width:
            raise ValueError("word too wide for the surface")
        if y + bounds.height - bounds.y >= height:
            raise ValueError("text to long for the surface")
        font.render_to(display, (x, y), None, black)
        x += bounds.width + space.width
    return x, y

,并且,如果我使用Afont,则会出现此错误:     AttributeError:“ pygame.font.Font”对象没有属性“ origin” 只有我可以使用freetype字体。为什么?我该如何解决?

0 个答案:

没有答案