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

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;
}
}
));

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