Text Rendering#

ppb supports basic text rendering: single font, single style, no wrapping. Rendered fonts are graphical Assets that can be used any place you’d use ppb.Image

class Label(ppb.sprite):
    image = ppb.Text("Hello, World", font=ppb.Font("resources/noto.ttf", size=12))

TrueType and OpenType fonts (both .ttf) are supported, but must be shipped with your game. (System fonts are not supported.)

Note that fonts require a size in points. This controls the size the text is rendered at, but the size on screen is still controlled by Sprite.size.

class ppb.Font(name, *, size, index=None)[source]#

A TrueType/OpenType Font

Parameters:
  • name – the filename to load

  • size – the size in points

  • index – the index of the font in a multi-font file (rare)

class ppb.Text(txt, *, font, color=(0, 0, 0))[source]#

A bit of rendered text.

Parameters:
  • txt – The text to display.

  • font – The font to use (a ppb.Font)

  • color – The color to use.