4.2.8 - Drawing Text


Text is slightly more complex. There are three things that need to be done.

  1. First, create a variable that holds information about the font to be used, such as what typeface and how big.
    font = SysFont(name, size, bold=False, italic=False)

  2. Second, create an image of the text. One way to think of it is that the program carves out a “stamp” with the required letters that is ready to be dipped in ink and stamped on the paper.
    text = font.render(text, antialias, color, background=None)
     

  3. Tthird, write where this image of the text should be stamped (or “blit'ed”) to the screen.
    screen.blit(text, [250, 250])


Starting from the pygame basic template write the commands inside the drawing section:

font = pygame.font.SysFont('Calibri', 25, True, False) # in line 47
text = font.render("My text",True,BLACK) # in line 48
screen.blit(text, [250, 250]) # in line 49

and save the script as simple_text.

Experiment combining different shapes and text and creating your own picture.