Text
Text in the world: any project font (or SDF for crisp scaling), wrapping, alignment, rich text ([color=..] [size=..] [wave] [shake]), localization keys and a typewriter reveal.
Type: TextNode · Category: Graphics & Rendering · Also found as: text, label2d, textlabel
Properties
Section titled “Properties”| Property | Type | Default | Description |
|---|---|---|---|
text |
string | "Text" |
The text; rich text markup when Rich Text is on, a locale key when Localized. |
font |
string | "" |
Project font (.ttf / .otf / .fnt; “” = the engine font). |
fontSize |
number | 24 |
Text size (px). Range 4 to 256. |
color |
color | #ffffffff |
Text colour (rich text [color] overrides it). |
align |
enum: Left, Center, Right |
Left |
Alignment of the lines within the text block. |
maxWidth |
number | 0 |
Wrap lines at this width (px); 0 = only at line breaks. Range 0 to 4000. |
lineSpacing |
number | 1.2 |
Line height as a multiple of the font size. Range 0.5 to 3. |
richText |
boolean | true |
Interpret [color=..] [size=..] [wave] [shake] tags. |
localized |
boolean | false |
The text is a key in the locale tables; shows the current language’s translation. |
sdf |
boolean | false |
Signed-distance-field rendering: stays sharp when scaled or zoomed (vector fonts). |
revealSpeed |
number | 0 |
Typewriter: characters per second (0 = all at once); emits “revealed” when done. Range 0 to 500. |
Plus the common properties every node has.
Lua methods
Section titled “Lua methods”Call them on the node (self.node in its script, or self.node:get_node("path")). Every node also has the Node methods.
TextNode:connect(event, handler)
Section titled “TextNode:connect(event, handler)”Connects a handler to one of this node’s events: revealed (The text finished revealing); the tree events; custom ones.
self.node:connect("revealed", function(value, source) Log.info("revealed") end)eventTextNodeEvent|stringhandlerfun(value:any, source: TextNode)
Returns integer id Connection id for disconnect
TextNode:get_property(path)
Section titled “TextNode:get_property(path)”Reads an Inspector property by its path (vectors and colours as tables); “script.
local value = self.node:get_property("text")pathTextNodeProperty|string
Returns any
TextNode:set_property(path, value, y)
Section titled “TextNode:set_property(path, value, y)”Sets an Inspector property by its path: vectors as {x, y} or x, y; colours as {r, g, b[, a]} 0..1 or “#rrggbb[aa]”; enums by name; “script.
self.node:set_property("text", "text")pathTextNodeProperty|stringvalueanyy?number
TextNode:text_restart()
Section titled “TextNode:text_restart()”TextNode: types the text out again (revealSpeed > 0).
self.node:get_node("Intro"):text_restart()In a scene file
Section titled “In a scene file”{ "type": "TextNode", "name": "Text", "position": [ 0, 0 ], "properties": { "text": "Text", "font": "", "fontSize": 24 }}