vanilladocs
vanillapunch.com
API / animation/action

animation/action

액션.

Action.

Actionextends Object

짝Counterpart: vanilla-engine Action

액션.

  • 순차적으로 스텝을 실행하는 스크립팅 방식의 액션 클래스.
  • 사용 예시:
const action = new Action()
    .wait(1.0, {
        started:   (target) => { },
        updated:   (progress, target) => { target.setLocalOpacity(progress); },
        completed: (target) => { }
    })
    .condition((target) => gameState.isReady())
    .call((target) => { target.playAnimation(); })
    .repeat(3, new Action().wait(0.5, { updated: (p, t) => { ... } }))
    .forever(new Action().wait(2.0));

action.start(myNode);

// 매 프레임:
action.step(timeDelta);

Action.

  • A scripting-style action class that runs steps sequentially.
  • Usage example:
const action = new Action()
    .wait(1.0, {
        started:   (target) => { },
        updated:   (progress, target) => { target.setLocalOpacity(progress); },
        completed: (target) => { }
    })
    .condition((target) => gameState.isReady())
    .call((target) => { target.playAnimation(); })
    .repeat(3, new Action().wait(0.5, { updated: (p, t) => { ... } }))
    .forever(new Action().wait(2.0));

action.start(myNode);

// Every frame:
action.step(timeDelta);
예제Example기다리고 부르고 반복하기Wait, call and repeat
import { Action } from "./build/vanilla.js";

const target = { opacity: 0, isReady: false };
const blinkAction = new Action();
blinkAction.wait(0.1);
const action = new Action();
action.wait(0.5, {
	updated: (progress, actionTarget) => {
		actionTarget.opacity = progress;
	}
});
action.call((actionTarget) => {
	actionTarget.isReady = true;
});
action.repeat(2, blinkAction);
action.start(target);
for (let frame = 0; frame < 60; ++frame) {
	action.step(1 / 60);
}
console.log(target.opacity, target.isReady, action.isDone());
생성자constructorconstructor()#0.0.9 부터since 0.0.9소스source

생성.

Constructor.

짝Counterpart: vanilla-engine Action.new

메서드methodwait(duration, callbacks = {})#0.0.9 부터since 0.0.9소스source

일정 시간 대기.

  • callbacks.started(target) : 스텝 시작 시 호출.
  • callbacks.updated(progress, target) : 매 프레임 호출. progress = 0~1.
  • callbacks.completed(target) : 스텝 완료 시 호출.

Waits for a set time.

  • callbacks.started(target) : called when the step starts.
  • callbacks.updated(progress, target) : called every frame. progress = 0~1.
  • callbacks.completed(target) : called when the step completes.
durationnumber
기다릴 시간. (초, 0 이하이면 다음 step 에서 바로 끝난다)Time to wait. (seconds, ends on the next step if 0 or less)
callbacks{ started?: Function, updated?: Function, completed?: Function }
{ started, updated, completed } 콜백. (모두 생략할 수 있다){ started, updated, completed } callbacks. (all optional)

반환ReturnsAction 이어 쓸 수 있게 이 액션.This action, for chaining.

짝Counterpart: vanilla-engine Action.wait

예제Example진행률 콜백 받기Receive progress callbacks
import { Action } from "./build/vanilla.js";

const action = new Action();
action.wait(1, {
	started: (target) => {
		console.log("started", target.name);
	},
	updated: (progress, target) => {
		target.progress = progress;
	},
	completed: (target) => {
		console.log("completed", target.progress);
	}
});
const target = { name: "fade", progress: 0 };
action.start(target);
action.step(0.5);
action.step(0.5);
console.log(action.isDone());
메서드methodcondition(conditionFn, callbacks = {})#0.0.9 부터since 0.0.9소스source

조건이 참이 될 때까지 대기. (조건 함수는 대상을 받는다)

  • callbacks.started(target) : 스텝 시작 시 호출.
  • callbacks.updated(target) : 조건 충족 전 매 프레임 호출.
  • callbacks.completed(target) : 조건 충족 시 호출.

Waits until the condition becomes true. (the condition function receives the target)

  • callbacks.started(target) : called when the step starts.
  • callbacks.updated(target) : called every frame until the condition is met.
  • callbacks.completed(target) : called when the condition is met.
conditionFnFunction
대상을 받아 참을 돌려주면 다음 스텝으로 넘어가는 함수. (step 마다 부른다)Function that receives the target and moves to the next step when it returns true. (called on every step)
callbacks{ started?: Function, updated?: Function, completed?: Function }
{ started, updated, completed } 콜백. (모두 생략할 수 있다){ started, updated, completed } callbacks. (all optional)

반환ReturnsAction 이어 쓸 수 있게 이 액션.This action, for chaining.

짝Counterpart: vanilla-engine Action.condition

메서드methodcall(fn)#0.0.9 부터since 0.0.9소스source

즉시 콜백 호출.

Calls a callback immediately.

fnFunction
대상을 받는 함수. (스텝이 시작되면 바로 부르고 다음 스텝으로 넘어간다)Function that receives the target. (called as soon as the step starts, then moves to the next step)

반환ReturnsAction 이어 쓸 수 있게 이 액션.This action, for chaining.

짝Counterpart: vanilla-engine Action.call

메서드methodrepeat(times, innerAction)#0.0.9 부터since 0.0.9소스source

내부 액션을 N회 반복. (0 이하이면 돌지 않고 넘어간다)

Repeats the inner action N times. (0 or less skips it without running)

timesnumber
반복 수. (0 이하이면 돌지 않고 넘어간다)Repeat count. (skipped without running if 0 or less)
innerActionAction
반복할 액션. (끝날 때마다 같은 대상으로 다시 start 한다)Action to repeat. (started again with the same target each time it finishes)

반환ReturnsAction 이어 쓸 수 있게 이 액션.This action, for chaining.

짝Counterpart: vanilla-engine Action.repeat

메서드methodforever(innerAction)#0.0.9 부터since 0.0.9소스source

내부 액션을 무한 반복.

Repeats the inner action forever.

innerActionAction
끝날 때마다 다시 start 할 액션.Action to start again each time it finishes.

반환ReturnsAction 이어 쓸 수 있게 이 액션.This action, for chaining.

짝Counterpart: vanilla-engine Action.forever

메서드methodrepeatWhile(conditionFn, innerAction)#0.4.0 부터since 0.4.0소스source

조건이 참인 동안 내부 액션을 반복. (조건 함수는 대상을 받는다)

Repeats the inner action while the condition is true. (the condition function receives the target)

conditionFnFunction
대상을 받아 참이면 한 번 더 도는 함수. (스텝을 시작할 때와 내부 액션이 끝날 때마다 부른다)Function that receives the target and runs one more time if true. (called when the step starts and each time the inner action finishes)
innerActionAction
반복할 액션.Action to repeat.

반환ReturnsAction 이어 쓸 수 있게 이 액션.This action, for chaining.

짝Counterpart: vanilla-engine Action.repeat_while

예제Example조건이 참인 동안 반복하기Repeat while a condition is true
import { Action } from "./build/vanilla.js";

const counter = { count: 0 };
const incrementAction = new Action();
incrementAction.call((target) => {
	target.count += 1;
});
const action = new Action();
action.repeatWhile((target) => {
	return target.count < 3;
}, incrementAction);
action.start(counter);
for (let frame = 0; frame < 10; ++frame) {
	action.step(1 / 60);
}
console.log(counter.count, action.isDone());
메서드methodstart(target)#0.0.9 부터since 0.0.9소스source

실행 시작. (처음 스텝부터)

  • 대상을 들고 있다가 step 이 그 대상을 콜백에 넘기고 getTarget 이 돌려준다. (러스트 판 start(node_tree, Some(node_id)))

Starts running. (from the first step)

  • Holds the target, so step passes it to the callbacks and getTarget returns it. (start(node_tree, Some(node_id)) in the Rust edition)
targetSystem.Object
콜백과 조건 함수에 넘길 대상. (undefined 이면 전의 대상을 그대로 쓴다)Target passed to callbacks and condition functions. (keeps the previous target if undefined)

반환ReturnsAction 이어 쓸 수 있게 이 액션.This action, for chaining.

짝Counterpart: vanilla-engine Action.start

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

대상을 들지 않고 실행 시작. (처음 스텝부터)

  • 첫 스텝의 시작 콜백까지 이 자리에서 target 으로 부르고, 대상은 들지 않는다. (getTarget 은 그대로)
  • 뒤로는 stepWith 에 매번 대상을 넘긴다. repeat, forever, loop 의 안쪽 액션도 이렇게 돈다.

Starts running without holding the target. (from the first step)

  • Calls up to the first step's started callback right here with target, and does not hold the target. (getTarget stays as it was)
  • After this, pass the target to stepWith every time. The inner actions of repeat, forever and loop run this way too.
targetSystem.Object
이번에 콜백과 조건 함수에 넘길 대상.The target to pass to the callbacks and condition functions this time.

반환ReturnsAction 이어 쓸 수 있게 이 액션.This action, for chaining.

짝Counterpart: vanilla-engine Action.start_with

예제Example대상을 매번 넘겨 돌리기Running by passing the target every time
import { Action } from "./build/vanilla.js";

const target = { opacity: 0 };
const action = new Action();
action.wait(1, {
	updated: (progress, actionTarget) => {
		actionTarget.opacity = progress;
	}
});
action.startWith(target);
action.stepWith(target, 0.5);
console.log(target.opacity, action.getTarget());
메서드methodstop()#0.0.9 부터since 0.0.9소스source

실행 중단.

Stops running.

짝Counterpart: vanilla-engine Action.stop

메서드methodstep(timeDelta)#0.0.9 부터since 0.0.9소스source

갱신. (매 프레임 호출)

  • start 로 든 대상을 콜백에 넘긴다. (러스트 판 step(node_tree, time_delta))

Updates. (call every frame)

  • Passes the target held by start to the callbacks. (step(node_tree, time_delta) in the Rust edition)
timeDeltanumber
지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)

짝Counterpart: vanilla-engine Action.step

메서드methodstepWith(target, timeDelta)#0.4.0 부터since 0.4.0소스source

대상을 넘겨 갱신. (매 프레임 호출)

  • start 전이거나 끝났으면 아무것도 하지 않는다. 든 대상 대신 target 을 콜백에 넘긴다.

Updates with a given target. (call every frame)

  • Does nothing before start or after it is done. Passes target to the callbacks instead of the held target.
targetSystem.Object
이번에 콜백과 조건 함수에 넘길 대상.The target to pass to the callbacks and condition functions this time.
timeDeltanumber
지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)

짝Counterpart: vanilla-engine Action.step_with

예제Example장면 갱신에서 대상을 넘겨 돌리기Running by passing the target from a scene update
import { Action } from "./build/vanilla.js";

const logo = { opacity: 0 };
const action = new Action();
action.wait(2, {
	updated: (progress, actionTarget) => {
		actionTarget.opacity = progress;
	}
});
action.startWith(logo);
action.stepWith(logo, 1);
action.stepWith(logo, 1);
console.log(logo.opacity, action.isDone());
메서드methodisDone()#0.0.9 부터since 0.0.9소스source

완료 여부 반환.

Returns whether it is complete.

반환Returnsboolean 모든 스텝을 마쳤거나 stop 했으면 참.True if all steps have finished or stop was called.

짝Counterpart: vanilla-engine Action.is_done

메서드methodisRunning()#0.0.9 부터since 0.0.9소스source

실행 중 여부 반환.

Returns whether it is running.

반환Returnsboolean start 한 뒤 아직 끝나지 않았으면 참.True if started and not finished yet.

짝Counterpart: vanilla-engine Action.is_running

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

타겟 반환.

Returns the target.

반환ReturnsSystem.Object start 에 넘긴 대상. 없으면 null.Target passed to start. null if none.

짝Counterpart: vanilla-engine Action.get_target