vanilladocs
vanillapunch.com
API / core/tween

core/tween

트윈.

Tween.

Tweenextends Object

짝Counterpart: vanilla-engine Tween

트윈.

  • setTarget(node) 로 대상 노드를 정하면 값 이름이 TweenProperty 이름인 값을 tick 마다 그 노드에 바로 쓴다. 대상 노드가 트윈이 처음 돈 때의 노드 트리에서 떨어지면(removeChild 등) 콜백 없이 조용히 끝난다.
  • duration 이 0 이하이면 바로 끝(진행률 1)으로 친다.

Tween.

  • Once the target node is set with setTarget(node), values whose names are TweenProperty names are written directly to that node every tick. If the target node leaves the node tree it was in when the tween first ran (removeChild, etc.), it ends quietly without callbacks.
  • If duration is 0 or less, it is treated as finished immediately (progress 1).
예제Example값 두 개를 0.5 초 동안 바꾸기Change two values over 0.5 seconds
import { Tween } from "./build/vanilla.js";

const tween = new Tween({ x: 0, alpha: 1 });
tween.to({ x: 100, alpha: 0 }, 0.5);
tween.easing(Tween.easingFunction.quadratic.easeOut);
tween.setUpdate((values) => {
	console.log(values.x, values.alpha);
});
tween.setComplete(() => {
	console.log("complete");
});
tween.start();
for (let step = 0; step < 5; ++step) {
	tween.tick(0.1);
}
console.log(tween.isFinished());
생성자constructorconstructor(initialValues)#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

initialValuesObject
시작 값 객체. (이름마다 숫자나 Vector2, 얕게 복사해 둔다)Start value object. (a number or Vector2 per name, kept as a shallow copy)

짝Counterpart: vanilla-engine Tween.new

정적staticstatic createNodeTween(node, tweenProperty, startValue, endValue, duration)#0.4.0 부터since 0.4.0소스source

노드 속성 하나를 움직이는 트윈 생성. (정적)

  • new Tween(시작값).to(목표값, duration).setTarget(node) 와 같다. 값 이름은 속성 이름이다.

Creates a tween that animates one node property. (static)

  • Same as new Tween(startValue).to(targetValue, duration).setTarget(node). The value name is the property name.
nodeWorldNode
움직일 노드.Node to move.
tweenPropertystring
TweenProperty 의 값.Value of a TweenProperty.
startValuenumber | Vector2
시작 값.Start value.
endValuenumber | Vector2
목표 값.Target value.
durationnumber
걸리는 시간. (초, 0 이하이면 바로 끝)Duration. (seconds, finishes at once if 0 or less)

반환ReturnsTween 만든 트윈. (아직 돌지 않는다, Scene.startTween 이나 start 로 시작한다)The created tween. (not running yet, start it with Scene.startTween or start)

짝Counterpart: vanilla-engine Tween.create_node_tween

예제Example씬에서 노드 위치를 움직이기Move a node position in a scene
import { Engine, EngineConfiguration, Scene, WorldNode, Tween, TweenProperty, 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 tween = Tween.createNodeTween(node, TweenProperty.localPosition, Vector2.create(0, 0), Vector2.create(200, 100), 0.5);
		tween.easing(Tween.easingFunction.cubic.easeInOut);
		tween.setComplete(() => {
			const localPosition = node.getLocalPosition();
			console.log(localPosition.x, localPosition.y);
		});
		this.startTween(tween);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
정적staticstatic findRootNode(node)#0.4.0 부터since 0.4.0소스source

노드의 맨 위 노드 반환.

Returns the topmost node of the node.

nodeNode
시작 노드.Start node.

반환ReturnsNode 부모를 끝까지 따라 올라간 노드. (부모가 없으면 그 노드)The node reached by following parents to the top. (the node itself if it has no parent)

짝Counterpart: vanilla-engine Tween.find_root_node

정적staticstatic easingFunction#0.0.8 부터since 0.0.8소스source

트윈 함수.

Tween function.

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

갱신.

Update.

timeDeltanumber
지난 시간. (초, 시작했고 끝나지 않았을 때만 넘긴다)Elapsed time. (seconds, advances only when started and not finished)

짝Counterpart: vanilla-engine Tween.tick

메서드methodto(properties, duration)#0.0.8 부터since 0.0.8소스source

목표값 설정.

Sets the target value.

propertiesSystem.Object
목표 값 객체. (시작 값에 같은 이름이 있고 꼴이 같은 것만 바뀐다, 숫자끼리나 Vector2 끼리)Target value object. (only names that exist in the start values with the same kind change, number to number or Vector2 to Vector2)
durationnumber
걸리는 시간. (초, 주지 않으면 그대로, 기본 1)Duration. (seconds, unchanged if omitted, default 1)

반환ReturnsTween 이 트윈. (이어 부르기)This tween. (for chaining)

짝Counterpart: vanilla-engine Tween.to

메서드methoddelay(amount)#0.0.8 부터since 0.0.8소스source

시작 전 대기 시간 설정.

Sets the delay before starting.

amountnumber
시작 전 대기 시간. (초)Wait time before starting. (seconds)

반환ReturnsTween 이 트윈. (이어 부르기)This tween. (for chaining)

짝Counterpart: vanilla-engine Tween.delay

메서드methodeasing(easingFunction)#0.0.8 부터since 0.0.8소스source

트윈 함수 설정.

Sets the tween function.

easingFunctionFunction
진행률(0 ~ 1)을 받아 바뀐 진행률을 돌려주는 함수. (Tween.easingFunction 의 것, 기본 linear)Function that takes the progress (0 ~ 1) and returns the eased progress. (one of Tween.easingFunction, default linear)

반환ReturnsTween 이 트윈. (이어 부르기)This tween. (for chaining)

짝Counterpart: vanilla-engine Tween.easing

메서드methodsetUpdate(callback)#0.0.8 부터since 0.0.8소스source

갱신 콜백 설정.

Sets the update callback.

callbackFunction
tick 마다 이번 값 객체를 받는 함수. (대기 시간 동안은 부르지 않는다)Function that receives the current value object on every tick. (not called during the delay)

반환ReturnsTween 이 트윈. (이어 부르기)This tween. (for chaining)

짝Counterpart: vanilla-engine Tween.set_update

메서드methodsetComplete(callback)#0.0.8 부터since 0.0.8소스source

완료 콜백 설정.

Sets the completion callback.

callbackFunction
진행률이 1 에 닿으면 한 번 부를 함수. (인자 없음, 대상 노드가 떨어져 끝날 때는 부르지 않는다)Function called once when the progress reaches 1. (no arguments, not called when it ends because the target node was detached)

반환ReturnsTween 이 트윈. (이어 부르기)This tween. (for chaining)

짝Counterpart: vanilla-engine Tween.set_complete

메서드methodsetTarget(node)#0.4.0 부터since 0.4.0소스source

대상 노드 설정. (값 이름이 TweenProperty 이름이면 이 노드에 쓴다)

Sets the target node. (values whose names are TweenProperty names are written to this node)

nodeWorldNode | null
대상 노드. (null 이면 노드에 쓰지 않고 콜백으로만 값을 준다)Target node. (if null, values are not written to a node and are only passed to the callback)

반환ReturnsTween 이 트윈. (이어 부르기)This tween. (for chaining)

짝Counterpart: vanilla-engine Tween.set_target

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

대상 노드 반환. (setTarget 을 하지 않았으면 null)

Returns the target node. (null if setTarget was not called)

반환ReturnsWorldNode | null 대상 노드. (없으면 null)Target node. (null if none)

메서드methodstart()#0.0.8 부터since 0.0.8소스source

시작.

Start.

짝Counterpart: vanilla-engine Tween.start

메서드methodstop()#0.0.8 부터since 0.0.8소스source

정지.

Stop.

짝Counterpart: vanilla-engine Tween.stop

메서드methodisFinished()#0.0.8 부터since 0.0.8소스source

완료 여부 반환.

Returns whether it is complete.

반환Returnsboolean 끝났으면 참. (stop 을 불렀거나 진행률이 1 에 닿았을 때)True if finished. (when stop was called or the progress reached 1)

짝Counterpart: vanilla-engine Tween.is_finished

함수Functions

함수functionapplyTweenProperty(node, tweenProperty, value)#0.4.0 부터since 0.4.0소스source

노드에 트윈 속성 값 쓰기. (노드 속성 이름이 아니면 아무것도 하지 않는다)

Writes a tween property value to the node. (does nothing if it is not a node property name)

nodeWorldNode
값을 쓸 노드.Node to write the value to.
tweenPropertystring
TweenProperty 의 값.Value of a TweenProperty.
valuenumber | Vector2
쓸 값. (Vector2 속성에 숫자를 주면 두 축에 같이 쓴다, 숫자 속성에 Vector2 를 주면 쓰지 않는다)Value to write. (a number given to a Vector2 property is written to both axes, a Vector2 given to a number property is not written)

TweenPropertyenum

짝Counterpart: vanilla-engine TweenProperty

트윈이 바로 쓰는 노드 속성 이름. (setTarget 으로 대상 노드를 정했을 때, 값 이름이 이 이름이면 그 노드에 쓴다)

  • Vector2 속성에 숫자를 주면 두 축에 같이 쓴다. (예: { localScale: 0 } → setLocalScale(Vector2.create(0, 0)))
  • 숫자 속성에 Vector2 를 주면 쓰지 않는다.

Node property names that a tween writes directly. (when a target node is set with setTarget, values with these names are written to that node)

  • Giving a number to a Vector2 property writes it to both axes. (e.g. { localScale: 0 } → setLocalScale(Vector2.create(0, 0)))
  • Giving a Vector2 to a number property does not write it.
이름Name값Value설명Description
localPositionlocalPosition로컬 위치. (Vector2, setLocalPosition)Local position. (Vector2, setLocalPosition)
localScalelocalScale로컬 크기 배율. (Vector2, setLocalScale)Local scale. (Vector2, setLocalScale)
localRotationlocalRotation로컬 회전. (숫자, 도, setLocalRotation)Local rotation. (number, degrees, setLocalRotation)
localOpacitylocalOpacity로컬 불투명도. (숫자, 0 ~ 1, setLocalOpacity)Local opacity. (number, 0 ~ 1, setLocalOpacity)
contentSizecontentSize내용 크기. (Vector2, 픽셀, setContentSize)Content size. (Vector2, pixels, setContentSize)