Beep8 logo

Text Renderer

Text Renderer Source Code

Textrenderer Methods

beep8.TextRenderer.drawText(x, y, text [,fontName])

Draws text at the given pixel coordinates, with no cursor movement.

Parameters

  • x (number): The x-coordinate.
  • y (number): The y-coordinate.
  • text (string): The text to draw.
  • [fontName] (string): The name of the font to use.

beep8.TextRenderer.getFont()

Get the current font.

Returns

  • (beep8.TextRendererFont): The current font.

beep8.TextRenderer.getFontByName(fontName)

Gets a font by name.

Parameters

  • fontName (string): The name of the font to get.

Returns

  • (beep8.TextRendererFont): The font.

beep8.TextRenderer.initAsync() async

Initializes the beep8.TextRenderer with the default font.

beep8.TextRenderer.loadFontAsync(fontName, fontImageFile [,tileSizeWidthMultiplier] [,tileSizeHeightMultiplier]) async

Loads a new font asynchronously.

Parameters

  • fontName (string): The name of the font.
  • fontImageFile (string): The URL of the image file for the font.
  • [tileSizeWidthMultiplier] (number): The tile size width multiplier for the font. (default: 1)
  • [tileSizeHeightMultiplier] (number): The tile size height multiplier for the font. (default: 1)

beep8.TextRenderer.measure(text [,font])

Measures the dimensions of the text.

Parameters

  • text (string): The text to measure.
  • [font] (beep8.TextRendererFont): The font to use for measurement. (default: null)

Returns

  • ({cols: number, rows: number): } The dimensions of the text.

beep8.TextRenderer.prepareCharMap()

Prepares the charMap array.

This is a list of character codes for each character in the chars string. This is used to look up the index of a character in the chars string.

beep8.TextRenderer.print(text [,font] [,wrapWidth])

Prints text at the current cursor position.

Parameters

  • text (string): The text to print.
  • [font] (beep8.TextRendererFont): The font to use for printing. (default: null)
  • [wrapWidth] (number): The width to wrap text at. (default: -1)

beep8.TextRenderer.printBox(width, height [,fill] [,borderCh])

Prints a box with borders.

Parameters

  • width (number): The width of the box.
  • height (number): The height of the box.
  • [fill] (boolean): Whether to fill the box. (default: true)
  • [borderCh] (number): The character to use for the border. (default: beep8.CONFIG.BORDER_CHAR)

beep8.TextRenderer.printCentered(text, width [,font])

Prints text centered within a given width.

Parameters

  • text (string): The text to print.
  • width (number): The width to center the text within.
  • [font] (beep8.TextRendererFont): The font to use. (default: null)

beep8.TextRenderer.printChar(ch, n [,font])

Prints a character a specified number of times.

Parameters

  • ch (number): The character to print.
  • n (number): The number of times to print the character.
  • [font] (beep8.TextRendererFont): The font to use. (default: null)

beep8.TextRenderer.printRect(width, height, ch)

Prints a rectangle of a specified character.

Parameters

  • width (number): The width of the rectangle.
  • height (number): The height of the rectangle.
  • ch (number): The character to fill the rectangle with.

beep8.TextRenderer.printTypewriter(text [,wrapWidth] [,delay] [,font]) async

Prints text character by character, as in a typewriter.

Parameters

  • text (string): The text to print.
  • [wrapWidth] (number): The width to wrap text at. (default: -1)
  • [delay] (number): The delay between characters in seconds. (default: 0.05)
  • [font] (beep8.TextRendererFont): The font to use. (default: null)

Returns

  • (Promise<void>): Resolves after the text is printed.

beep8.TextRenderer.regenColors()

Regenerates the colors for all fonts.

beep8.TextRenderer.setFont(fontName)

Sets the current font.

Parameters

  • fontName (string): The name of the font to set.

Returns

  • (void): * @throws {Error} If the font is not found or its dimensions are not compatible.

beep8.TextRenderer.setTileFont(fontName)

Sets the current tiles font.

Parameters

  • fontName (string): The name of the font to set.

beep8.TextRenderer.spr(ch, x, y)

Prints a character as a “sprite” at a raw x, y position.

Parameters

  • ch (number): The character to print.
  • x (number): The x-coordinate.
  • y (number): The y-coordinate.

beep8.TextRenderer.wrapText(text, wrapWidth, fontName)

Wraps text to a given width.

Parameters

  • text (string): The text to wrap.
  • wrapWidth (number): The width to wrap the text to.
  • fontName (beep8.TextRendererFont): The font to use.

Returns

  • (string): The wrapped text.

More Beep8 Docs

Actors Documentation

Async Documentation

Core Functions

Input Documentation

App Intro Documentation

Joystick Documentation

Menu Documentation

Music Documentation

Particle System Documentation

Passcodes Documentation

Public API

Random Numbers Documentation

Scene Documentation

SFX Documentation

Text Renderer

Tilemap Documentation

Utilities Documentation