Text Renderer
Textrenderer Methods
b8.TextRenderer.drawBox(width, height, [fill, [borders])
Draws 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)
- [borders] (Object): The borders to use.
Returns
- (void):
b8.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.
Returns
- (void):
b8.TextRenderer.getFont()
Get the current font.
Returns
- (b8.TextRendererFont): The current font.
b8.TextRenderer.getFontByName(fontName)
Gets a font by name.
Parameters
- fontName (string): The name of the font to get.
Returns
- (b8.TextRendererFont): The font.
b8.TextRenderer.initAsync() async
Initializes the b8.TextRenderer with the default font.
Returns
- (Promise<void>):
b8.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)
Returns
- (Promise<void>):
b8.TextRenderer.measure(text, [font)
Measures the dimensions of the text.
Parameters
- text (string): The text to measure.
- [font (b8.TextRendererFont): The font to use for measurement. (default: null)
Returns
- ({cols: number, rows: number): } The dimensions of the text.
b8.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.
Returns
- (void):
b8.TextRenderer.print(text, [font, [maxWidth)
Prints text at the current cursor position.
Parameters
- text (string): The text to print.
- [font (b8.TextRendererFont): The font to use for printing. (default: null)
- [maxWidth (number): The maximum width to wrap text at. (default: -1)
Returns
- (void):
b8.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: b8.CONFIG.BORDER_CHAR)
Returns
- (void):
b8.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 (b8.TextRendererFont): The font to use. (default: null)
Returns
- (void):
b8.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 (b8.TextRendererFont): The font to use. (default: null)
Returns
- (void):
b8.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.
Returns
- (void):
b8.TextRenderer.printRight(text, width, [font)
Prints text right-aligned within a given width.
Parameters
- text (string): The text to print.
- width (number): The width to right-align the text within.
- [font (b8.TextRendererFont): The font to use. (default: null)
Returns
- (void):
b8.TextRenderer.printStyledBox(width, height, [options)
Draws a box using a named style preset or explicit border definition.
Parameters
- width (number): The width of the box.
- height (number): The height of the box.
- [options (Object): Rendering options. (default: {})
Returns
- (void):
b8.TextRenderer.printTypewriter(text, [maxWidth, [delay, [font) async
Prints text character by character, as in a typewriter.
Parameters
- text (string): The text to print.
- [maxWidth (number): The width to wrap text at. (default: -1)
- [delay (number): The delay between characters in seconds. (default: 0.05)
- [font (b8.TextRendererFont): The font to use. (default: null)
Returns
- (Promise<void>): Resolves after the text is printed.
b8.TextRenderer.regenColors()
Regenerates the colors for all fonts.
Returns
- (void):
b8.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.
b8.TextRenderer.setTileFont(fontName)
Sets the current tiles font.
Parameters
- fontName (string): The name of the font to set.
Returns
- (void):
b8.TextRenderer.spr(ch, x, y, [font, [direction)
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.
- [font (b8.TextRendererFont): The font to use. (default: null)
- [direction (number): The direction to face (0=up, 1=right, 2=down, 3=left). (default: 0)
Returns
- (void):
b8.TextRenderer.wrapText(text, maxWidth, fontName)
Wraps text to a given width.
Parameters
- text (string): The text to wrap.
- maxWidth (number): The width to wrap the text to.
- fontName (b8.TextRendererFont): The font to use.
Returns
- (string): The wrapped text.