vanilladocs
vanillapunch.com
API / effect/trailrenderer

effect/trailrenderer

트레일 렌더러.

Trail renderer.

TrailRendererextends Component

짝Counterpart: vanilla-engine TrailRenderer

트레일 렌더러.

  • 노드가 지나간 자리를 점으로 기록해 굵기 / 색이 잦아드는 띠로 그린다. (유니티 TrailRenderer 의 2D 대응)
  • 사용:
const trail = node.addComponent(TrailRenderer);
trail.setTime(0.5);
trail.setWidth(14, 0);
trail.setColors(new Color(0.4, 0.8, 1, 0.9), new Color(0.4, 0.8, 1, 0));

Trail renderer.

  • Records the path the node has passed as points and draws it as a band whose width / color fade out. (2D counterpart of Unity's TrailRenderer)
  • Usage:
const trail = node.addComponent(TrailRenderer);
trail.setTime(0.5);
trail.setWidth(14, 0);
trail.setColors(new Color(0.4, 0.8, 1, 0.9), new Color(0.4, 0.8, 1, 0));
예제Example움직이는 노드 뒤에 빛나는 띠 남기기Leave a glowing trail behind a moving node
import { Engine, EngineConfiguration, Scene, WorldNode, TrailRenderer, Tween, TweenProperty, Color, Vector2 } from "./build/vanilla.js";

class MainScene extends Scene {
	initialize(engine) {
		super.initialize(engine);
		const node = new WorldNode();
		const root = this.getRoot();
		root.addChild(node);
		const trailRenderer = node.addComponent(TrailRenderer);
		trailRenderer.setTime(0.5);
		trailRenderer.setWidth(14, 0);
		trailRenderer.setColors(new Color(0.4, 0.8, 1, 0.9), new Color(0.4, 0.8, 1, 0));
		trailRenderer.setAdditive(true);
		const tween = Tween.createNodeTween(node, TweenProperty.localPosition, Vector2.create(40, 180), Vector2.create(600, 180), 0.8);
		tween.setComplete(() => {
			console.log(trailRenderer.getPointCount());
		});
		this.startTween(tween);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
Leave a glowing trail behind a moving node
생성자constructorconstructor()#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine TrailRenderer.new

메서드methodtick(timeDelta)#0.3.0 부터since 0.3.0소스source

갱신. (점 기록 + 노화)

Update. (point recording + aging)

timeDeltanumber
지난 시간. (초, 점이 늙고 수명이 지난 점은 빠진다)Elapsed time. (seconds, points age and those past their lifetime are removed)
메서드methoddraw(graphic)#0.3.0 부터since 0.3.0소스source

출력. (세그먼트마다 굵기 / 색 보간, 노드 원점 기준 상대 좌표로 그린다)

Draw. (interpolates width / color per segment, draws in coordinates relative to the node origin)

graphicGraphic
그릴 그래픽.Graphic to draw with.
메서드methodclear()#0.3.0 부터since 0.3.0소스source

흔적 지우기.

Clears the trail.

짝Counterpart: vanilla-engine TrailRenderer.clear

메서드methodcalculateDrawnRect(rect)#0.4.0 부터since 0.4.0소스source

그리는 사각형 셈하기. (오버라이드: 점을 이은 띠를 모두 품는 사각형, 노드 내용 좌표)

  • 점은 노드 자리를 뺀 자리에 그리므로 지금 노드 자리로 옮기고, 두 굵기 가운데 큰 것의 반과 한 단위 여유만큼 넓힌다. (선 끝과 이음까지)
  • 점이 있으면 tick 마다, 지움(clear)과 굵기를 바꾸면 다시 셈하게 알린다. 점이 둘보다 적으면 그리지 않으므로 크기 0.

Calculates the drawn rectangle. (Override: a rectangle enclosing the band joining the points, in node content coordinates)

  • Points are drawn relative to the node position, so they are moved by the current node position and grown by half the larger of the two widths plus one unit of margin. (Covering line ends and joins)
  • Recalculation is requested every tick while points exist, on clear, and when the width changes. With fewer than two points nothing is drawn, so the size is 0.
rectRect
그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)

반환Returnsboolean 알면 참.True if known.

예제Example지나간 자리를 품는 사각형A rectangle enclosing the path travelled
import { WorldNode, TrailRenderer, Rect, Vector2 } from "./build/vanilla.js";

const node = new WorldNode();
const trailRenderer = node.addComponent(TrailRenderer);
trailRenderer.setWidth(10, 0);
trailRenderer.tick(0.016);
node.setLocalPosition(Vector2.create(100, 0));
trailRenderer.tick(0.016);
const drawnRect = Rect.zero();
console.log(trailRenderer.calculateDrawnRect(drawnRect), drawnRect.position.x, drawnRect.size.x);
메서드methodsetTime(pointLifetime)#0.3.0 부터since 0.3.0소스source

점이 남는 시간 설정. (띠의 길이를 정한다)

Sets how long points stay. (sets the trail length)

pointLifetimenumber
점이 남는 시간. (초)How long points remain. (seconds)

짝Counterpart: vanilla-engine TrailRenderer.set_time

메서드methodsetMinVertexDistance(minVertexDistance)#0.3.0 부터since 0.3.0소스source

점 사이 최소 거리 설정.

Sets the minimum distance between points.

minVertexDistancenumber
이보다 가까이 움직이면 점을 더하지 않는다. (픽셀, 기본 3)No point is added while moving closer than this. (pixels, default 3)

짝Counterpart: vanilla-engine TrailRenderer.set_min_vertex_distance

메서드methodsetWidth(startWidth, endWidth)#0.3.0 부터since 0.3.0소스source

굵기 설정. (갓 생긴 점의 굵기에서 끝 굵기로 줄어든다)

Sets the width. (shrinks from the width of a fresh point to the end width)

startWidthnumber
갓 생긴 점의 굵기. (픽셀, 기본 10)Width of a fresh point. (pixels, default 10)
endWidthnumber
수명이 다한 점의 굵기. (픽셀, 기본 0)Width of a point at the end of its lifetime. (pixels, default 0)

짝Counterpart: vanilla-engine TrailRenderer.set_width

메서드methodsetColors(startColor, endColor)#0.3.0 부터since 0.3.0소스source

색 설정. (갓 생긴 점의 색에서 끝 색으로 바뀐다)

Sets the colors. (changes from the color of a fresh point to the end color)

startColorColor | string
갓 생긴 점의 색. (복사해 둔다)Color of a fresh point. (kept as a copy)
endColorColor | string
수명이 다한 점의 색. (복사해 둔다)Color of a point at the end of its lifetime. (kept as a copy)

짝Counterpart: vanilla-engine TrailRenderer.set_colors

메서드methodsetAdditive(isAdditive)#0.3.0 부터since 0.3.0소스source

가산 합성 여부 설정.

Sets whether to use additive blending.

isAdditiveboolean
참이면 "lighter" 로 섞어 그린다. (기본 거짓)If true, draws blended with "lighter". (default false)

짝Counterpart: vanilla-engine TrailRenderer.set_additive

메서드methodsetEmitting(isEmitting)#0.3.0 부터since 0.3.0소스source

점 만들기 여부 설정.

Sets whether to make points.

isEmittingboolean
거짓이면 새 점을 만들지 않는다. (남은 띠는 잦아든다)If false, no new points are created. (the remaining band fades out)

짝Counterpart: vanilla-engine TrailRenderer.set_emitting

메서드methodgetPointCount()#0.3.0 부터since 0.3.0소스source

남은 점 수 반환.

Returns the remaining point count.

반환Returnsnumber 남은 점 수.Remaining point count.

짝Counterpart: vanilla-engine TrailRenderer.get_point_count