Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Nightre/Rapid.js/llms.txt
Use this file to discover all available pages before exploring further.
TextTexture extends Texture and bridges the HTML5 Canvas 2D text rendering API with the WebGL pipeline. Each instance maintains an internal HTMLCanvasElement, measures and draws the current text with the configured style, then uploads the result as a WebGL texture. The canvas is sized at device-pixel-ratio resolution and the Texture.scale property is set to 1 / dpr, so text appears crisp on high-DPR screens without any extra work.
Both the
text and style setters automatically re-render the canvas and
re-upload to the GPU. You do not need to call update() manually in most
cases.Creating a TextTexture
Userapid.texture.createTextTexture() rather than constructing the class directly.
ITextStyle
All style fields are optional. Unset fields fall back to their default values.CSS font family name. Any font available in the browser can be used, including
web fonts loaded with
@font-face — as long as the font has finished loading
before the TextTexture is first rendered.Font size in logical CSS pixels. The internal canvas scales this by
dpr so
the rendered pixels are always sharp.CSS font weight string, e.g.
"normal", "bold", "700".Text fill color or style. Accepts any value valid as a Canvas 2D
fillStyle — a CSS color string, a CanvasGradient, or a CanvasPattern.
When omitted the text interior is not filled.Text outline color or style. Accepts the same types as
fill. Has no visual
effect if strokeThickness is 0.Width of the outline stroke in logical CSS pixels. The outline is rendered
before the fill so it appears behind the filled text. Set to
0 to disable.Horizontal alignment anchor. Affects
offsetX on the texture:| Value | offsetX | Effect |
|---|---|---|
"left" | 0 | Draw position is the left edge of the text. |
"center" | -width / 2 | Draw position is the horizontal center. |
"right" | -width | Draw position is the right edge. |
Vertical alignment anchor. Affects
Other
offsetY on the texture. The most useful
values are:| Value | offsetY | Effect |
|---|---|---|
"top" | 0 | Draw position is the top of the text. |
"middle" | -height / 2 | Draw position is the vertical center. |
"bottom" | -height | Draw position is the bottom. |
CanvasTextBaseline values ("alphabetic", "hanging",
"ideographic") map to offsetY = 0.ITextOptions
ITextOptions is the interface accepted by createTextTexture(). It extends
both ITextStyle and ITextureOptions, adding one additional field:
The initial text string to display. Defaults to an empty string if omitted.
The value can be updated at any time via the
text setter.ITextStyle (font, fill, stroke, align,
baseline) and ITextureOptions
(textureFilter, wrap, premultipliedAlpha, key) are also valid in this object.
Properties
text (getter / setter)
The current text string displayed by this texture.
style (getter / setter)
The current ITextStyle configuration. The setter performs a partial
merge — only the properties you supply are changed; all others retain their
current values. The texture is re-uploaded after every set.
flipY
Always true on TextTexture. Instructs the renderer to vertically flip the
UV coordinates when drawing, correcting the orientation difference between the
HTML5 Canvas coordinate system (top-left origin) and WebGL (bottom-left origin).
Methods
update()
Manually re-renders the internal canvas and re-uploads the texture to the GPU.
You only need to call this if you have bypassed the text/style setters and
mutated internal state directly.
void
Alignment and offset Behaviour
TextTexture uses offsetX and offsetY on the base Texture class to shift
the draw position without requiring you to adjust the coordinates you pass to
drawSprite(). The offsets are recomputed every time update() runs.
Drawing
TextTexture is a Texture subclass and can be passed directly to any Rapid.js
draw call.
Live Updates
Multi-line Text
Split text across multiple lines with the\n newline character. Line height
and gap are measured using Canvas 2D fontBoundingBoxAscent and
fontBoundingBoxDescent so spacing matches the actual font metrics.
Destroying a TextTexture
TextTexture inherits destroy() from Texture. Call it when the label is no
longer needed to release the GPU texture and decrement the BaseTexture
reference count.