Difference between revisions of "Drawing text"
(Created page with "=Method 1= When drawing text you need to use the blit method of the screen you have declared. You can change the font and size: <syntaxhighlight lang=python> # initialize fon...") |
(No difference)
|
Revision as of 17:01, 30 June 2018
Method 1
When drawing text you need to use the blit method of the screen you have declared. You can change the font and size:
# initialize font; must be called after 'pygame.init()' to avoid 'Font not Initialized' error
myfont = pygame.font.SysFont("monospace", 15)
# render text
label = myfont.render("Some text!", 1, (255,255,0))
screen.blit(label, (100, 100))
Method 2
You can use variables to pass into the previous example:
pygame.font.init()
font_path = "./fonts/newfont.ttf"
font_size = 32
fontObj = pygame.font.Font(font_path, font_size)
label = fontObj.render("Some text!", 1, (255,255,0))
screen.blit(label, (100, 100))