# misc/toucheffect (vanilla.js 0.4.0)

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

파티클용 방사형 그라디언트 텍스처. (흰색으로 구워 셰이더 틴트로 착색)
- WebGL2 에는 그라디언트 API 가 없으므로 오프스크린 2D 캔버스에 1회만 굽는다.

## TouchParticle extends Object

터치 입자.

예제: 입자 하나의 수명과 자리를 한 걸음 줄이고 옮기기

```js
import { TouchParticle, Vector2 } from "./build/vanilla.js";

const touchParticle = new TouchParticle();
touchParticle.position = Vector2.create(100, 100);
touchParticle.velocity = Vector2.create(30, -60);
touchParticle.radius = 20;
const timeDelta = 0.1;
touchParticle.life -= timeDelta * 2.5;
const step = touchParticle.velocity.multiply(timeDelta);
touchParticle.position = touchParticle.position.add(step);
const opacity = touchParticle.life / touchParticle.maxLife;
console.log(opacity, touchParticle.position.x, touchParticle.position.y);
```

- `position` (field, since 0.0.8): 자리. (픽셀, TouchEffect 노드 기준)
  - returns Vector2
- `velocity` (field, since 0.0.8): 속도. (픽셀 / 초)
  - returns Vector2
- `life` (field, since 0.0.8): 남은 수명. (1 에서 시작해 초당 2.5 씩 줄고 0 이하면 지운다)
  - returns number
- `maxLife` (field, since 0.0.8): 처음 수명. (불투명도는 life / maxLife)
  - returns number
- `radius` (field, since 0.0.8): 반지름. (픽셀)
  - returns number
- `constructor()` (constructor, since 0.0.8): 생성.

## TouchEffect extends WorldNode

터치 효과.

예제: 누른 자리에 빛 입자 뿌리기

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

const touchEffect = new TouchEffect();

class MainScene extends Scene {
	initialize(engine) {
		super.initialize(engine);
		const root = this.getRoot();
		root.addChild(touchEffect);
		for (let index = 0; index < 8; ++index) {
			touchEffect.createTouchParticle(320, 180);
		}
	}

	touchPress(viewInputPosition) {
		super.touchPress(viewInputPosition);
		for (let index = 0; index < 8; ++index) {
			touchEffect.createTouchParticle(viewInputPosition.x, viewInputPosition.y);
		}
	}
}

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

- `constructor()` (constructor, since 0.0.8): 생성.
- `tick(timeDelta)` (method, since 0.0.8): 갱신.
  - `timeDelta` number: 지난 프레임부터의 시간. (초)
- `pushTransform(graphic)` (method, since 0.0.11): 출력 상태 시작.
  - `graphic` Graphic: 그릴 그래픽.
- `draw(graphic)` (method, since 0.0.8): 출력.
  - `graphic` Graphic: 그릴 그래픽.
- `popTransform(graphic)` (method, since 0.0.11): 출력 상태 종료.
  - `graphic` Graphic: 그릴 그래픽.
- `createTouchParticle(x, y)` (method, since 0.0.8): 터치 파티클 생성.
  - `x` number: 입자를 낼 X. (이 노드 기준 좌표, 10 픽셀 안에서 흔든다)
  - `y` number: 입자를 낼 Y. (이 노드 기준 좌표, 10 픽셀 안에서 흔든다)
- `updateTouchParticles(timeDelta)` (method, since 0.0.8): 터치 파티클 갱신.
  - `timeDelta` number: 지난 프레임부터의 시간. (초)
- `drawTouchParticles(graphic)` (method, since 0.0.8): 터치 파티클 출력.
  - `graphic` Graphic: 그릴 그래픽.
