在显示时,我有时会创建一个名为Funk的新文件。这将有字体、大小等。这是类的代码:import pygame
def text_to_screen(screen, text, x, y, size = 50,
color = (200, 000, 000), font_type = 'data/fonts/orecrusherexpand.ttf'):
try:
text = str(text)
font = pygame.font.Font(font_type, size)
text = font.render(text, True, color)
screen.blit(text, (x, y))
except Exception, e:
print 'Font Error, saw it coming'
raise e
然后当我想显示文本时,输入该文本并更新,例如score I do:Funk.text_to_screen(screen, 'Text {0}'.format(score), xpos, ypos)
如果只是普通文本没有更新:Funk.text_to_screen(screen, 'Text', xpos, ypos)
在第一个示例中,您可能会注意到{0}。这是因为当使用.format(whatever)时,它将被更新。如果你有类似于Score的东西,那么你将对Score做{0},然后对target Score做{1}。format(Score,targetscore)