# misc/floatingtext (vanilla.js 0.4.0)

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

떠오르는 텍스트 관리 노드. (데미지 숫자 / +코인 등)

## FloatingText extends WorldNode

떠오르는 텍스트 관리 노드. (데미지 숫자 / +코인 등)
- spawn() 으로 띄우면 위로 떠오르며 사라진다. 끝난 라벨 노드는 재사용한다.
- 씬 뿌리에 addChild 해 두고 월드 좌표로 띄운다.
- 사용:
    const floatingText = new FloatingText();
    scene.getRoot().addChild(floatingText);
    floatingText.spawn("-120", position, { color: new Color(1, 0.4, 0.4, 1) });

예제: 누른 자리에 피해 숫자 띄우기

```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): 생성.
- `spawn(text, worldPosition, options = {})` (method, since 0.3.0): 텍스트 띄우기.
  - `text` string: 띄울 글.
  - `worldPosition` Vector2: 띄울 자리. (이 노드의 지역 좌표로 놓는다, 씬 뿌리에 붙였으면 월드 좌표, 가로로 jitter 만큼 흔든다)
  - `options` object: { color?, fontSize = 22, rise = 46, duration = 0.8, jitter = 10, bold = true }
- `tick(timeDelta)` (method, since 0.3.0): 갱신. (떠오름 + 사라짐 + 회수)
  - `timeDelta` number: 지난 프레임부터의 시간. (초)
- `getActiveCount()` (method, since 0.3.0): 떠 있는 항목 수 반환.
  - returns number: 떠 있는 항목 수.
- `clear()` (method, since 0.3.0): 모두 지우기.
