Class BitmapText

All Implemented Interfaces:
Cloneable

public class BitmapText extends DrawingSprite
Text made from image glyphs, such as font065.png for 'A'. Add it to a stage like a sprite. Its position is the top of the first line, with each line aligned left, centred or right. Spaces and line breaks do not load images. Image data uses the library cache, so changing text does not create sprites or reload files. Use ordinary Text for normal system/TrueType fonts.
  • Constructor Details

    • BitmapText

      public BitmapText(String pattern)
      Parameters:
      pattern - image path with an integer format, e.g. "assets/font%03d.png"
  • Method Details

    • showText

      public void showText(String text)
      Parameters:
      text - text to show, including spaces and newlines
    • getContent

      public String getContent()
      Returns:
      the text being shown
    • setFont

      public void setFont(String pattern)
      Parameters:
      pattern - glyph path with one integer format for the Unicode code point
    • addGlyph

      public void addGlyph(char character, String path)
      Assigns an image to a special character, such as a controller button. Overrides remain in effect when setFont() changes the ordinary glyphs.
      Parameters:
      character - the character to replace
      path - its image or built-in costume name
    • setAlign

      public void setAlign(TextAlign align)
      Parameters:
      align - LEFT, CENTER or RIGHT (DEFAULT means LEFT)
    • setSpaceWidth

      public void setSpaceWidth(double width)
      Parameters:
      width - width of a space, in unscaled pixels
    • setLetterSpacing

      public void setLetterSpacing(double spacing)
      Parameters:
      spacing - gap between characters; negative values allow italic glyphs to overlap
    • setLineSpacing

      public void setLineSpacing(double spacing)
      Parameters:
      spacing - extra pixels between lines
    • getWidth

      public double getWidth()
      Overrides:
      getWidth in class Sprite
      Returns:
      the displayed text's width, including the sprite's size
    • getHeight

      public double getHeight()
      Overrides:
      getHeight in class Sprite
      Returns:
      the displayed text's height, including line spacing and sprite size
    • draw

      public void draw(Drawing drawing)
      Description copied from class: DrawingSprite
      Draws the sprite; called every frame on the game thread.
      Overrides:
      draw in class DrawingSprite
      Parameters:
      drawing - the current frame's canvas