# misc/floatingtext (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/misc/floatingtext/

Floating text manager node. (damage numbers / +coins, etc.)

## FloatingText extends WorldNode

Floating text manager node. (damage numbers / +coins, etc.)
- Text shown with spawn() floats upward and fades out. Finished label nodes are reused.
- Add it to the scene root with addChild and spawn in world coordinates.
- Usage:
    const floatingText = new FloatingText();
    scene.getRoot().addChild(floatingText);
    floatingText.spawn("-120", position, { color: new Color(1, 0.4, 0.4, 1) });

Example: Pop up damage numbers where pressed

```js
import { Engine, EngineConfiguration, Scene, FloatingText, Vector2, Color } from "./build/vanilla.js";

const floatingText = new FloatingText();

class MainScene extends Scene {
	initialize(engine) {
		super.initialize(engine);
		const root = this.getRoot();
		root.addChild(floatingText);
		floatingText.spawn("-120", Vector2.create(320, 180), { color: new Color(1, 0.4, 0.4, 1) });
		floatingText.spawn("+5", Vector2.create(200, 220), { fontSize: 30, duration: 1.2, jitter: 0 });
		console.log(floatingText.getActiveCount());
	}

	touchPress(viewInputPosition) {
		super.touchPress(viewInputPosition);
		floatingText.spawn("+1", viewInputPosition);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
```

- `constructor()` (constructor, since 0.3.0): Constructor.
- `spawn(text, worldPosition, options = {})` (method, since 0.3.0): Spawns text.
  - `text` string: Text to show.
  - `worldPosition` Vector2: Position to show at. (placed in this node's local coordinates, world coordinates if attached to the scene root, jittered horizontally by jitter)
  - `options` object: { color?, fontSize = 22, rise = 46, duration = 0.8, jitter = 10, bold = true }
- `tick(timeDelta)` (method, since 0.3.0): Update. (float + fade + recycle)
  - `timeDelta` number: Time since the last frame. (Seconds)
- `getActiveCount()` (method, since 0.3.0): Returns the number of floating items.
  - returns number: Number of floating items.
- `clear()` (method, since 0.3.0): Clears all.
