# cocos.text module

Text support

CocosNodes subclasses supporting text. They use a suitable pyglet text object to do the work. Functionality other that the one common to all cococsnodes, except ‘opacity’, is provided by the member ‘element’ , which is the underlying pyglet object.

class `HTMLLabel`(text='', position=(0, 0), **kwargs)

  Bases: `cocos.text.TextElement`

  HTML formatted text label (supports a subset of HTML 4.01)

  Functionality other that the one common to all cococsnodes, except ‘opacity’, is provided by the member ‘element’ , which is the underlying pyglet object. The undelying pyglet object is pyglet.text.HTMLLabel.

  For pyglet 1.1.4 the available init keyword arguments are

    - location: Location object for loading images referred to in the document. By default, the working directory is used.

    - width: Width of the label in pixels, or None

    - height: Height of the label in pixels, or None

    - anchor_x: “left”, “center” or “right”.

    - anchor_y: one of “bottom”, “baseline”, “center” or “top”.

    - multiline : bool

    - dpi : float, defaults to 96

  `klass`

    alias of `pyglet.text.HTMLLabel`

class `Label`(text='', position=(0, 0), **kwargs)

  Bases: `cocos.text.TextElement`

  Plain text support

  Functionality other that the one common to all cococsnodes, except ‘opacity’, is provided by the member ‘element’ , which is the underlying pyglet object. The undelying pyglet object is pyglet.text.Label

  For pyglet 1.1.4 the available init keyword arguments are

    - font_name: Font family name(s); the first matching name is used

    - font_size: Font size, in points

    - bold: bool

    - italic: bool

    - color: (int, int, int, int) Font colour, as RGBA

    - width: Width of the label in pixels, or None

    - height: Height of the label in pixels, or None

    - anchor_x: one of “left”, “center” or “right”

    - anchor_y : one of “bottom”, “baseline”, “center” or “top”

    - align : applies when width is supplied. One of “left”, “center” or “right”.

    - multiline: bool

    - dpi: Resolution of the fonts in this layout. Defaults to 96.

  `klass`

    alias of `pyglet.text.Label`

class `PygletRichLabel`(text='', font_name=None, font_size=None, bold=False, italic=False, color=None, x=0, y=0, width=None, height=None, anchor_x='left', anchor_y='baseline', align='left', multiline=False, dpi=None, batch=None, group=None)

  Bases: `pyglet.text.DocumentLabel`

  This is not a CocosNode - let instantiation be handled by RichLabel

  Helper class for RichLabel

class `RichLabel`(text='', position=(0, 0), **kwargs)

  Bases: `cocos.text.TextElement`

  displays pyglet attributed (rich) text

  The undelying pyglet object is a custom, cocos provided PygletRichLabel element, subclass of pyglet.text.DocumentLabel.

  For pyglet 1.1.4 the available init keyword arguments are

    - font_name: Font family name(s); first matching is used

    - font_size: Font size, in points.

    - bold: bool

    - italic: bool

    - color : (int, int, int, int) or None

    - width: Width of the label in pixels, or None

    - height: Height of the label in pixels, or None

    - anchor_x: “left”, “center” or “right”

    - anchor_y: one of “bottom”, “baseline”, “center” or “top”

    - align : only when a width is supplied. One of “left”, “center”, “right”.

    - multiline : bool

    - dpi : Resolution of the fonts in this layout. Defaults to 96.

  `klass`

    alias of `PygletRichLabel`

class `TextElement`(text='', position=(0, 0), **kwargs)

  Bases: `cocos.cocosnode.CocosNode`

  Base class for all cocos text

  Provides the CocosNode interfase and a pyglet Batch to store parts Functionality other that the one common to all cococsnodes, except ‘opacity’, is provided by the member ‘element’ , which is the underlying pyglet object.

  `create_element`()
  `draw`()

    This is the function you will have to override if you want your subclassed `CocosNode` to draw something on screen.

    You must respect the position, scale, rotation and anchor attributes. If you want OpenGL to do the scaling for you, you can:

        def draw(self):
            glPushMatrix()
            self.transform()
            # ... draw ..
            glPopMatrix()

  property `opacity`