There are three text objects for the game: the score, the game title and the game over text. All three are setup using the label class from the adafruit_display_text library.

The score_text will hold the score of the game and update constantly. new_game_text is shown when the PyBadge is booted up with the code to say "BLINKA JUMP" and game_over_text shows "GAME OVER" when you lose a game.

You can either hard code the text that will be displayed or leave it open so that it defaults to show nothing and can be updated later in the code. In the case of all three of these text objects, the default text is left empty by using text = "       ". The number of spaces between the quotation marks matters, since a string that is longer than the spacing will cause an error.

score_text = "      "
font = terminalio.FONT
score_color = 0x0000FF

#  text for "game over" graphic
game_over_text = label.Label(font, text = "         ", color = 0xFF00FF)
# score text
score_area = label.Label(font, text=score_text, color=score_color)
#  text for "new game" graphic
new_game_text = label.Label(font, text = "           ", color = 0xFF00FF)

After the setup, all of the text objects' default positions are defined with x and y coordinates. Following that, a display group for the text objects is created and all of the text objects are added to that group. Finally, the text_group is added to the main display group, which also has the sprites that were created earlier in the code.

# coordinants for text areas
score_area.x = 57
score_area.y = 6
game_over_text.x = 13
game_over_text.y = 30
new_game_text.x = 8
new_game_text.y = 30
# creating a text display group
text_group = displayio.Group()
text_group.append(score_area)
text_group.append(game_over_text)
text_group.append(new_game_text)
#  adding text group to main display group
group.append(text_group)

This guide was first published on Jul 01, 2020. It was last updated on Jul 01, 2020.

This page (Creating Text) was last updated on Sep 29, 2021.

Text editor powered by tinymce.