Text
The Text component draws strings from a dynamic glyph atlas. Give the entity a
UINode and the text lays out inside the flexbox box (wrapped, aligned, sorted
with sibling UI); without a box it renders as a free world-space label anchored
to the entity origin. Spawn one in code with spawnUIEntity({ text: … }) or add
Text in the inspector.
import { defineSystem, addStartupSystem, GetWorld, spawnUIEntity, TextAlign, px } from 'esengine';
const buildHud = defineSystem([GetWorld()], (world) => { spawnUIEntity({ world, node: { width: px(240), height: px(40) }, text: { content: 'Score: 0', fontSize: 24, align: TextAlign.Left }, });});addStartupSystem(buildHud);The two glyph pipelines
Section titled “The two glyph pipelines”Every glyph is rasterized once into a shared atlas and drawn as textured quads.
renderMode picks how it is rasterized, per Text:
Bitmap— glyphs rasterize with Canvas2D at the effective on-screen pixel size: device pixels × the canvas design-resolution fit are folded into rasterization, so quads blit 1:1 with native antialiasing and font hinting. DOM-crisp at any window size — the sharpest choice for static UI.Sdf— each glyph rasterizes once into a signed-distance field and the shader lays a ~1px screen-space coverage ramp on the edge (the msdfgen/TextMeshPro technique). The edge stays crisp under dynamic scaling — animated zoom, scale tweens, world-space labels — where a bitmap would blur or shimmer.Auto(default) — bitmap while the entity’s own world scale is 1 (within ±2%; the canvas fit is already compensated in the bitmap path), SDF the moment the entity scales. DOM-crisp static UI and zoom-stable animated text with no configuration. Under a perspective camera world text is always SDF: a world unit covers a different number of pixels at every depth, so there is no size a bitmap glyph could be drawn at to land 1:1. Text at 128 screen pixels or more (far zoomed in, say) is also SDF, from a field wide enough for an outline of about a quarter of the font size, and returns to bitmap when it shrinks again.
So a pulsing “LEVEL UP!” banner needs nothing special — Auto switches it to
SDF while it scales:
import { defineSystem, Query, Mut, Res, Time, Transform, Text,} from 'esengine';
// Tween the banner's scale; Auto routes the text to the SDF pipeline// while scale ≠ 1, so the glyph edges stay crisp mid-zoom.const pulseBanner = defineSystem([Query(Mut(Transform), Text), Res(Time)], (q, time) => { for (const [, tr] of q) { const s = 1 + 0.25 * Math.sin(time.elapsed * 4); tr.scale.x = s; tr.scale.y = s; }});Force Sdf when text is born scaled or lives in world space under an
orthographic camera that zooms freely; force Bitmap when you know the text
never scales and want hinting even under tiny per-frame scale noise. A bitmap
glyph is never rasterized larger than half an atlas page (512 px): past that it
is drawn from 512 px and the log says once that the text reads better as Sdf.
Text properties
Section titled “Text properties”Defaults below are the component defaults (what the inspector shows).
| Property | Type | Default | Description |
|---|---|---|---|
content |
string | '' |
The string to display. \n hard-breaks lines. |
i18nKey |
string | '' |
Localization key. Non-empty ⇒ content becomes derived: resolved from the Localization catalogs every frame (see below). |
font |
font asset | none | A font file the project ships (.ttf / .otf / .woff / .woff2, or a bitmap .fnt). Wins over fontFamily when set (see Custom fonts). |
fontFamily |
string | '' |
A font family the host already has, resolved by the platform’s text stack (see Custom fonts). Empty uses the project’s default font family (Settings → Runtime → Text; Arial unless changed). |
fontSize |
number | 24 |
Size in design px — the same units as UINode px() sizes. The design-resolution fit and device pixel ratio are compensated at rasterization. |
color |
Color | {1,1,1,1} |
Fill color (per-channel 0..1). |
align |
TextAlign |
Left |
Horizontal alignment: Left / Center / Right. |
verticalAlign |
TextVerticalAlign |
Top |
Vertical alignment: Top / Middle / Bottom. |
wordWrap |
boolean | true |
Wrap lines at the box width (needs a box: a UINode, or the Text’s own boxWidth). |
overflow |
TextOverflow |
Visible |
What text too big for its box does (needs a box): Visible keeps it all; Clip and Ellipsis drop the lines past the box height and trim a line past its width; Shrink sets the type smaller, a whole pixel at a time, until it fits both (line height and letter spacing shrink with it, down to 1px); ResizeHeight keeps every line and grows the entity’s ContentRect to the height they take. |
underline |
boolean | false |
A bar under each line, cut from the font’s own underscore so its thickness and depth are the font’s. |
boxWidth / boxHeight |
number | 0 |
The layout box of a Text with no UINode, in px. 0 means no box (the entity origin is the box). With a box, alignment, wrapping and overflow work inside it while the text stays world content, sorted by layer. A UINode, when present, decides the box instead. |
boxPivot |
Vec2 | (0.5, 0.5) |
Where the entity origin sits in that box, as a fraction from its left and bottom edges: (0.5, 0.5) is the centre, (0, 1) the top-left corner. It is the anchor point of a Cocos or Unity rect transform. |
lineHeight |
number | 1.2 |
Line spacing as a ratio of fontSize (baseline-to-baseline = lineHeight × fontSize). |
letterSpacing |
number | 0 |
Extra space after every glyph, in the same px as fontSize; negative draws the glyphs closer. Wrapping, alignment and overflow measure with it. It is CSS’s letter-spacing and a Cocos Label’s spacingX. |
bold / italic |
boolean | false |
Base font style (rich-text <b>/<i> layer on top). |
strokeColor |
Color | {0,0,0,1} |
Outline color. |
strokeWidth |
number | 0 |
Outline width in px; 0 disables. An SDF glyph’s own edge is pushed outward and a bitmap glyph is grown, so it stays the glyph’s shape at any width (see below). |
shadowColor |
Color | {0,0,0,1} |
Drop-shadow color. The shadow and the outline fade with the text’s own color alpha, so a label faded out leaves neither behind. |
shadowOffsetX / shadowOffsetY |
number | 0 |
Shadow offset in px. |
shadowBlur |
number | 0 |
Softens the shadow, in px. 0 is a hard offset copy; above that the shadow spreads into a ring, so it reads as a soft mass under the glyphs rather than a second stamp of them. A blur with no offset is a halo. |
richText |
boolean | false |
Parse inline rich-text markup. |
renderMode |
TextRenderMode |
Auto |
Glyph pipeline: Auto / Bitmap / Sdf (see above). |
layer |
number | 0 |
Draw layer of a Text with no UINode, read like Sprite.layer, so a world label can sit in front of or behind the content around it. Ignored under a UINode, where the UI render order decides. |
enabled |
boolean | true |
Render toggle (the editor’s eye icon uses it too). |
Alignment — with and without a box
Section titled “Alignment — with and without a box”align (Left / Center / Right) and verticalAlign (Top / Middle / Bottom) place the text block within its box — the nine combinations.
One rule covers both cases: align / verticalAlign position the text block
within its box, and a missing box collapses to a zero-size box at the entity
origin — so the same fields anchor a free label instead of silently doing
nothing.
- With a
UINodebox (the entity has aUINodewith a non-zero laid-out size): each line aligns horizontally within the box width — independent ofwordWrap, which only decides whether lines break at that width — andverticalAligndistributes the block’s vertical slack (Middlesplits it,Bottompushes the block down). - With the
Text’s own box (noUINode, butboxWidth/boxHeightset): the same placement, wrapping and overflow, with the box standing whereboxPivotputs it relative to the entity — so a world label can wrap and align inside a rectangle without joining a Canvas. - Without a box (no
UINode, or a 0×0 one, and noboxWidth/boxHeight): the block anchors to the entity origin.align: Leftputs the left edge at the origin,Centercenters the block on it,Rightends at it;verticalAlignanchors top/middle/bottom edge the same way. This is what you want for world-space labels — damage numbers, nameplates — where “center on the entity” is one field, not math.
Outlines
Section titled “Outlines”strokeWidth + strokeColor outline the glyphs, shadow* drops a shadow behind
them. Both are drawn from the same atlas as the fill, so a styled label still
batches with an unstyled one.
An outline moves the glyph’s edge — it is not a fan of copies. SDF glyphs
carry a distance to their own edge, so the outline is that edge pushed outward:
the same quads draw the same shape, grown. The width you ask for is converted
through the atlas’s spread and render size, so it means the same thing at every
fontSize and every camera zoom, and asking for more than the atlas can dilate
degrades to the widest real outline instead of flooding the glyph’s cell.
Bitmap glyphs have no distance to push, so each one is grown instead: the atlas places the glyph again, dilated by the width (in the texels it was rasterized at), and the outline draws those grown glyphs once behind the fill. The ring is solid and antialiased at any width, and a grown glyph is cached per size and width like the glyph itself. (Up to 0.97 this path stamped the glyph in eight directions, which turned anything wider than a hairline into eight ghost copies of the label.) A bitmap font without a baked outline keeps that stamp, the one glyph source the atlas cannot grow.
A shadowBlur above 0 stamps the shadow at the centre plus a ring of eight
around it, with each tap’s alpha inverted out of the compositing equation so the
stack lands at the alpha you asked for. Unlike the outline it softens the edge
rather than moving it, which is why the two are separate fields.

The Rich Text playground: edit the markup and the rendered text above it updates.
Rich text
Section titled “Rich text”Set richText: true and mark up content with inline tags. Styles nest as a
stack; a closing tag pops the innermost style. Anything that does not parse as a
known tag renders literally (so a stray < cannot eat your text).
| Markup | Effect |
|---|---|
<b>…</b> |
Bold run. |
<i>…</i> |
Italic run. |
<color=#RRGGBB>…</color> |
Colored run; #RRGGBBAA adds alpha. A name works too: <color=red> (black, white, red, green, blue, yellow, cyan, magenta, orange, gray, purple, pink, brown). |
<font size=32>…</font> |
Run at another font size (size="32" also parses); the shared baseline is kept. <size=32>…</size> is the same. |
<br/> |
A line break. |
<u>, <s>, <outline …>, <on click=…> |
Accepted so text written for other engines does not show raw tags; the text is kept and the style (or click) is not applied. |
<img src="…" width=24 height=24 /> |
Inline image — an icon flowed in with the text (see below). |
import { defineSystem, addStartupSystem, GetWorld, spawnUIEntity, px } from 'esengine';
const buildToast = defineSystem([GetWorld()], (world) => { spawnUIEntity({ world, node: { width: px(360), height: px(48) }, text: { content: 'Found <color=#ffd75a><b>Iron Sword</b></color> <font size=12>(rare)</font>', fontSize: 18, richText: true, }, });});addStartupSystem(buildToast);The parser is exported as parseRichText(input), returning RichTextRun[] — a
TextSegment (text, bold, italic, color, fontSize) or ImageSegment
per run — if you want to drive a custom pipeline from the same markup.
Inline images
Section titled “Inline images”<img src="…" width=N height=N valign=baseline|middle|top|bottom offsetX=N offsetY=N scale=N tint=#RRGGBB /> (self-closing, src required) flows an image
inline with the text. The same rich-text layout that places the glyphs places
the image box — valign anchors it on the line, width/height/scale size
it, offsetX/Y nudge it, tint recolors it — and it renders as a child image
quad under the Text. src resolves through Assets.loadTexture, so it is a
project-relative texture path.
Measuring text
Section titled “Measuring text”measureText(text, opts) answers “how big will this string render?” without
spawning an entity — for layout that must size to content up front, e.g. a
ListView itemHeight(index) for wrapped chat bubbles. It measures through the
same Canvas2D source and the same wrap algorithm the renderer uses, so measured
wraps match rendered ones. On a headless host (no DOM) it falls back to an
average-glyph estimate.
import { measureText, px, spawnUIEntity, defineSystem, addStartupSystem, GetWorld } from 'esengine';
const buildBubble = defineSystem([GetWorld()], (world) => { const message = 'You have been invited to join the guild "Night Watch".'; const m = measureText(message, { fontSize: 16, maxWidth: 260 }); spawnUIEntity({ world, node: { width: px(280), height: px(m.height + 20) }, // pad the measured height visual: { color: { r: 0.13, g: 0.15, b: 0.2, a: 1 } }, text: { content: message, fontSize: 16, wordWrap: true }, });});addStartupSystem(buildBubble);MeasureTextOptions |
Default | Description |
|---|---|---|
fontSize |
— (required) | Size in display px. |
fontFamily |
'Arial' |
Font family. |
bold / italic |
false |
Style (affects advances). |
letterSpacing |
0 |
Extra px between glyphs. |
maxWidth |
— | Word-wrap width; 0/omitted = single line. |
lineHeight |
fontSize × 1.2 |
Line height in display px (note: px, not the component’s ratio). |
TextMetrics |
Description |
|---|---|
width |
Width of the widest line, display px. |
lineCount |
Lines after wrapping plus explicit \n. |
height |
lineCount × lineHeight — the height to size a box to. |
Custom fonts
Section titled “Custom fonts”There are two ways to say which typeface, and they end in the same place — a family name the platform’s text stack rasterizes with.
Ship the font with the game (Text.font). Import a .ttf / .otf / .woff2 into
the project and assign it to the font slot in the inspector. It is a real asset
reference, so it rides the machinery every other asset slot rides: dependency tracking,
cook inclusion, @uuid: refs, hot update, ref counting. The loader registers the file
with the platform’s text stack under a family name it mints, and Text uses that name —
so a shipped font is not a second text path, just another way to arrive at a family. This
is the answer on native, where there is no page to load a web font into.
Name a font the host already has (fontFamily). Resolved by the platform’s
Canvas2D on the web (or the OS font matcher on native) when glyphs rasterize — system
fonts, or a web font the page loads itself (CSS @font-face or the FontFace API). The
SDK does not fetch these; make sure a web font is loaded before the text first renders,
or its glyphs rasterize with the fallback font.
font wins when both are set. Prefer it for anything your brand depends on: fontFamily
alone silently falls back to a different typeface on a machine that lacks the family, and
that failure only shows up on someone else’s device.
Bitmap font assets (.fnt / .bmfont) load through the asset pipeline —
Assets.loadFont(ref) resolves the .fnt, loads its page texture, and returns a
FontResult ({ handle }). They serve both text components:
Text.fontdraws the font from its page texture, through the same layout as any other font — wrapping, alignment, the box,Shrink, shadow and outline all work. The font’s own metrics are used, scaled byfontSizeover the size it was drawn at (info size), so a label is as big as the font’s author made it at that size. A bitmap font always draws as a bitmap, whateverrenderModesays.BitmapTextis the world-space renderer for pre-baked glyph art: itsfontfield references the loaded asset, withtext,color,fontSize,align,spacing,parallax, andlayerfields.
A page is a plain RGBA image to tint unless its common line says otherwise. A font
that bakes its outline into the page — the glyph in the red channel, glyph and
outline together in alpha — declares it in BMFont’s own channel flags
(alphaChnl=2 redChnl=0). Text then draws it in two passes: the outline ring
first, in strokeColor, then the glyph in color. strokeWidth only says whether
there is a ring (the page’s ring is drawn, not grown), and without one only the
glyph is drawn, so the outline can be any colour, translucent, or absent.
Preloading glyphs
Section titled “Preloading glyphs”A character is made the first time it appears, and that takes time: one or two go unnoticed, but the first page of a novel is hundreds of new characters, all in one frame. If you know what is coming, make them on a loading screen:
import { preloadGlyphs } from 'esengine';
const preload = preloadGlyphs(app, label, chapterText, { budgetMs: 8 });showProgress(() => preload.progress);await preload.done;// ...when the chapter is over:preload.release();- The font, size, style and render mode are read from
label’sText, which need not be visible yet. - It spends at most
budgetMsa frame (4 by default). Repeated characters cost nothing. - Preloaded glyphs hold their atlas pages until
release(). A 1024×1024 page takes 4 MB of video memory and holds a few hundred characters at novel sizes. - Text in a rich-text size or an outline is another atlas cell, and is still made when it first shows.
Localization
Section titled “Localization”Set i18nKey instead of hand-writing content: while a Localization resource
exists (install localizationPlugin), a per-frame system resolves the key
through the catalogs and writes the result into content — so setLocale
re-flows every bound label on the next frame. A missing key resolves to the key
itself (visible and greppable), and with no Localization resource the authored
content stands. See Localization.
Best practices
Section titled “Best practices”- Leave
renderModeonAuto— hand-pickSdfonly for text that is born scaled,Bitmaponly to pin hinting on text you know never scales. - Give UI text a
UINodebox so wrapping and alignment have a width to work against; go boxless only for world-space labels anchored to an entity. fontSizeis design px — size text in the same units as yourpx()layout and let the engine handle DPR and the design-resolution fit.- Measure before you size —
measureTextuses the renderer’s own wrap, so content-sized boxes (chat rows, tooltips) come out exact. - Bind labels with
i18nKey, not by writing translated strings intocontent— locale switches then re-flow for free. - Prefer markup over entity-splitting for emphasis: one rich Text beats three plain ones glued with flexbox.
See also
Section titled “See also”- UI — the component model overview.
- UI Layout — the
UINodebox that text aligns and wraps within. - UI Components —
createTextInputfor editable text. - UI Theme — themed text color roles and type scale.
- UI Binding — drive
contentfrom reactive signals. - Localization — catalogs, locales, and
i18nKeyresolution.