drawText
import { drawText } from 'pixi-silk/text';
function drawText(
g: SilkGraphics,
text: string,
x: number,
y: number,
style?: DrawTextStyle
): SilkGraphics;
Starts a new path on g, lays out text and adds one glyph shape per character. It returns
g, so you paint the glyphs with fill and stroke like any shape. The whole string draws in
the same call as the rest of the object, and the object can batch with others. A stroke is an
outline. A fill with blur and an offset (translateTransform) is a shadow. A gradient runs
across each glyph.
Glyphs come from SdfAtlas.shared. Their distance field reaches about a quarter of the font
size past the ink, so wider strokes and blurs are cut there. Colour glyphs (emoji) draw in one
colour: use SilkText for those. When the atlas fills up it starts over and its version
changes: graphics drawn before then show the wrong letters until you draw them again.
Parameters#
| Parameter | Type |
|---|---|
g | SilkGraphics |
text | string |
x | number |
y | number |
style | DrawTextStyle |
Returns#
Example#
import { SilkGraphics } from 'pixi-silk';
import { drawText } from 'pixi-silk/text';
const g = new SilkGraphics();
g.roundRect(0, 0, 220, 64, 16).fill(0x1c1c1e);
drawText(g, '$1,250.00', 110, 32, { fontSize: 28, fontWeight: 700, anchor: 0.5, tabularNumbers: true }).fill(0xffffff);
app.stage.addChild(g);