Skip to content

1681-engine / index / FloatingText

Class: FloatingText ​

Defined in: src/fx/FloatingText.ts:52

Floating text — damage numbers, pickups, "+1" — drawn from bitmap fonts and reused rather than created and destroyed each time: a crowded fight throws dozens a second, and as canvas text each one repainted a canvas at resolution 4 and uploaded it. A label keeps its font, so spent ones are pooled per style and only their string changes. Fonts are baked ahead (warm): a style first met mid-fight baked its glyph pages on that frame.

Constructors ​

Constructor ​

ts
new FloatingText(stage, options): FloatingText;

Defined in: src/fx/FloatingText.ts:59

Parameters ​

ParameterType
stageStage
optionsFloatingTextOptions

Returns ​

FloatingText

Methods ​

clear() ​

ts
clear(): void;

Defined in: src/fx/FloatingText.ts:150

Destroys every pooled label (a scene ending); labels still out are the scene's to free.

Returns ​

void


float() ​

ts
float(
   x, 
   y, 
   text, 
   style, 
   options?
): BitmapLabel;

Defined in: src/fx/FloatingText.ts:128

A label that pops, rises, fades and goes back to the pool by itself, on the stage's own tweens.

Parameters ​

ParameterType
xnumber
ynumber
textstring
styleFloatingTextStyle
optionsFloatOptions

Returns ​

BitmapLabel


install() ​

ts
install(style): void;

Defined in: src/fx/FloatingText.ts:87

Bakes one style's font now.

Parameters ​

ParameterType
styleFloatingTextStyle

Returns ​

void


release() ​

ts
release(t, style): void;

Defined in: src/fx/FloatingText.ts:114

Hands a finished label back for reuse.

Parameters ​

ParameterType
tBitmapLabel
styleFloatingTextStyle

Returns ​

void


take() ​

ts
take(
   x, 
   y, 
   text, 
   style
): BitmapLabel;

Defined in: src/fx/FloatingText.ts:92

A label ready to animate: shown, opaque, unscaled, anchored at its bottom centre on (x, y).

Parameters ​

ParameterType
xnumber
ynumber
textstring
styleFloatingTextStyle

Returns ​

BitmapLabel


warm() ​

ts
warm(
   styles, 
   delayMs?, 
   gapMs?
): () => void;

Defined in: src/fx/FloatingText.ts:73

Bakes the fonts of styles, one a task starting delayMs from now, so no frame pays for them all at once — ten at once froze a world's first frame half a second (each font measures and kerns every glyph). Returns a cancel.

Parameters ​

ParameterTypeDefault value
stylesreadonly FloatingTextStyle[]undefined
delayMsnumber1000
gapMsnumber50

Returns ​

() => void

Released under the MIT License.