Skip to content

Text & Image

Text

Renders styled text into a Sprite texture automatically via TextPlugin.

Setup: Add Transform, Sprite, UIRect, and Text to an entity.

PropertyTypeDefaultDescription
contentstring''Text content
fontFamilystring'Arial'Font family name
fontSizenumber24Font size in pixels
colorColor{r:1, g:1, b:1, a:1}Text color RGBA
alignTextAlignLeftLeft (0), Center (1), Right (2)
verticalAlignTextVerticalAlignTopTop (0), Middle (1), Bottom (2)
wordWrapbooleantrueEnable word wrapping
overflowTextOverflowVisibleVisible (0), Clip (1), Ellipsis (2)
lineHeightnumber1.2Line height multiplier
richTextbooleanfalseEnable rich text parsing
strokeColorColor{r:0, g:0, b:0, a:0}Text outline color
strokeWidthnumber0Text outline width in pixels
shadowColorColor{r:0, g:0, b:0, a:0.5}Drop shadow color
shadowBlurnumber0Shadow blur radius
shadowOffsetXnumber0Shadow horizontal offset
shadowOffsetYnumber0Shadow vertical offset

Modifying Text at Runtime

import { defineSystem, addSystem, Query, Mut, Text } from 'esengine';
addSystem(defineSystem(
[Query(Mut(Text))],
(query) => {
for (const [entity, text] of query) {
text.content = 'Updated!';
text.fontSize = 32;
}
}
));

Rich Text

Enable the richText property to use inline formatting tags:

text.richText = true;
text.content = '<color=#FF0000>Red</color> and <b>bold</b> text';

Supported tags:

TagDescriptionExample
<color=#RRGGBB>Text color<color=#FF0000>red</color>
<b>Bold<b>bold text</b>
<i>Italic<i>italic text</i>
<img src="path"/>Inline image<img src="icons/star.png"/>

Tags can be nested: <color=#00FF00><b>green bold</b></color>

Stroke & Shadow

Add outlines and drop shadows to any text:

// Outline
text.strokeColor = { r: 0, g: 0, b: 0, a: 1 };
text.strokeWidth = 2;
// Drop shadow
text.shadowColor = { r: 0, g: 0, b: 0, a: 0.5 };
text.shadowBlur = 4;
text.shadowOffsetX = 2;
text.shadowOffsetY = 2;

Stroke and shadow work with both plain text and rich text. In rich text mode, strokes render correctly across all text runs (all strokes are drawn before any fills to prevent visual overlap).

Image

Displays images with support for slicing, tiling, and fill modes.

PropertyTypeDefaultDescription
texturenumberTexture asset handle
colorColor{r:1, g:1, b:1, a:1}Color tint
imageTypeImageTypeSimpleSimple (0), Sliced (1), Tiled (2), Filled (3)
fillMethodFillMethodHorizontalHorizontal (0), Vertical (1)
fillOriginFillOriginLeftLeft (0), Right (1), Bottom (2), Top (3)
fillAmountnumber1Fill progress 0–1
preserveAspectbooleanfalseMaintain aspect ratio
tileSizeVec2{x:32, y:32}Tile size in pixels (used when imageType is Tiled)
layernumber0Render layer
materialnumber0Custom material handle (0 = default)
enabledbooleantrueVisibility toggle

Example: Score Display

import { defineTag, defineComponent, defineSystem, addSystem, Query, Mut, Changed, Text } from 'esengine';
const ScoreDisplay = defineTag('ScoreDisplay');
const GameState = defineComponent('GameState', { score: 0 });
addSystem(defineSystem(
[Query(Mut(Text), ScoreDisplay), Query(Changed(GameState))],
(displays, stateQuery) => {
if (stateQuery.isEmpty()) return;
const [, state] = stateQuery.single()!;
for (const [, text] of displays) {
text.content = `Score: ${state.score}`;
}
}
));

Uses Change Detection to only update text when the score actually changes.

Next Steps