pygame - How to display text with font & color?
You can use your own custom fonts by setting the font path using pygame.font.Font
pygame.font.Font(filename, size): return Font
example:
pygame.font.init()font_path = "./fonts/newfont.ttf"font_size = 32fontObj = pygame.font.Font(font_path, font_size)
Then render the font using fontObj.render and blit to a surface as in veiset's answer above. :)
I have some code in my game that displays live score. It is in a function for quick access.
def texts(score): font=pygame.font.Font(None,30) scoretext=font.render("Score:"+str(score), 1,(255,255,255)) screen.blit(scoretext, (500, 457))
and I call it using this in my while loop:
texts(score)