TagText

TagText is a special Tag that draws pixel-exact text to the screen. It has several advantages over the text() and font() functions such as the transformation methods that can be called on tags and the resource savings that result from compiling the text to a display list. TagText can also be conveniently subclassed to create more specialized text tags.

TagText(parent, name, size, typeface)

  • parent ... the world or another tag in which this tag should be nested.
  • name ... the name of this tag, names have to be unique within the parent element
  • size ... size of the font
  • typeface ... a key for build-in typefaces or a file path to a TrueType file. See font() for valid keys.

<tagtext>.setText(text)
  • text ... that will be printed by the TagText object

<tagtext>.setColor(r, g, b, a)
  • r, g, b, a ... red, green, blue, alpha values for the text color, floats from 0.0 to 1.0

Relevant examples: tagtext.py , spritetext.py , text.py , ALL

In Context

class Atlantis(World):
    def onSetup(self):
        self.name = "Typo"
        
        tt= TagText(self, 'count', 21)
        tt.setText('You can read.')
        tt.setColor(1.0, 0.5, 0.5, 1.0)
        tt.moveBy(10, 20)
Initiated by Stephan Hechenberger
Thanks to CADRE's 103