Text
┗> Object > Class
The Text object, made for displaying formatted text.
If you're looking for text which writes itself out over time, see DialogueText.
Constructor
Text(text: string, x: number, y: number, w: number?, h: number?, options: TextSettings?)
@param text — The text to display.
@param x — The X position of the text.
@param y — The Y position of the text.
@param w — The width of the text box. Defaults to the screen size if not specified.
@param h — The height of the text box. Defaults to the screen size if not specified.
@param options — The text's settings.
Arguments:
| text: string | The text to display. |
| x: number | The X position of the text. |
| y: number | The Y position of the text. |
| w: number? | The width of the text box. Defaults to the screen size if not specified. |
| h: number? | The height of the text box. Defaults to the screen size if not specified. |
| options: TextSettings? | The text's settings. |
Methods
Text:cloneState(state: table)
A helper function to avoid deep-cloning the entire state table.
Arguments:
| state: table | The state to clone. |
Returns:
| state: table | The cloned state. |
Text:drawChar(node: TextNode, state: TextState, use_color: boolean)
Draws a character from a TextNode and a TextState.
This is where all the styling happens, as well as the onDrawText event.
Arguments:
| node: TextNode | The TextNode to draw. |
| state: TextState | The TextState to draw with. |
| use_color: boolean | Whether to use the draw color as the base color instead of white. |
Text:drawToCanvas(func: function, clear: boolean?)
Draws to the text canvas.
Arguments:
| func: function | The function which draws to the canvas. |
| clear: boolean? | Whether to clear the canvas before drawing. |
Text:getCharPosition(node: any, state: any)
Arguments:
| node: any | |
| state: any |
Returns:
| 1: unknown | |
| 2: unknown |
Text:getNodeSize(node: any, state: any, include_scale: any)
Arguments:
| node: any | |
| state: any | |
| include_scale: any |
Returns:
| 1: integer | |
| 2: number |
Text:getTextColor(state: any, use_base_color: any)
Arguments:
| state: any | |
| use_base_color: any |
Returns:
| 1: unknown | |
| 2: unknown | |
| 3: unknown | |
| 4: number |
Text:isStyleAnimated(style: string)
Checks whether a text style is animated or not.
Arguments:
| style: string | The style to check. |
Returns:
| is_animated: boolean | Whether the style is animated or not. |
Text:isTrue(text: string)
A helper function to check if a string in a modifier is a "true" value.
Arguments:
| text: string | The text to check. |
Returns:
| is_true: boolean | Whether the text is a "true" value or not. |
Text:onAddToStage(stage: Object)
Arguments:
| stage: Object | The base class of all objects in Kristal. |
Text:processInitialNodes()
Processes the initial text nodes.
Text:processNode(node: TextNode, dry: boolean)
Processes a text node. If dry is true, the node will be processed without actually drawing anything, used for calculating text size and alignment.
Arguments:
| node: TextNode | The node to process. |
| dry: boolean | Whether to process the node without drawing anything, used for calculating text size and alignment. |
Text:processStyle(style: string)
An override function for processing a text style.
Arguments:
| style: string | The style to process. |
Returns:
| handled: boolean | Whether the style was handled or not. |
Text:registerCommand(command: any, func: any, options: any)
Arguments:
| command: any | |
| func: any | |
| options: any |
Text:resetState()
Resets the TextState to the default values. Used when setting new text.
Text:setText(text: string)
Sets the text to display. This may be slow if called frequently, so please set text with caution.
Arguments:
| text: string | The text to display. |
Text:textToNodes(input_string: any)
Converts a string of text into text nodes.
Arguments:
| input_string: any |
Returns:
| 1: table | |
| 2: string |
Fields
Text.display_text: string
The displayed text, without modifiers.
Text.nodes: TextNode[]
The text nodes.
Text.state: TextState
The current state of the text, used for processing modifiers and drawing the text.
Undocumented
Text.COLORS: table
The default colors available for text modifiers. Can be extended with the onTextColor event.
Text.COMMANDS: table
The default modifiers which exist. Can be extended with the registerTextCommands event.
Text.canvas: love.Canvas
A Canvas is used for off-screen rendering. Think of it as an invisible screen that you can draw to, but that will not be visible until you draw it to the actual visible screen. It is also known as "render to texture".
By drawing things that do not change position often (such as background items) to the Canvas, and then drawing the entire Canvas instead of each item, you can reduce the number of draw operations performed each frame.
In versions prior to love.graphics.isSupported("canvas") could be used to check for support at runtime.
Text.text_color: number, [2]? }
Three values representing a color, with an optional alpha value. Values are between 0 and 1.