vanilladocs
vanillapunch.com
API / animation/action

animation/action

액션. (차례로 스텝을 실행하는 스크립트 꼴 연출)

  • 원본 animation/action.js 를 옮긴 것이다. wait / condition / call / repeat / forever / loop 스텝을 쌓고, start 뒤 매 프레임 step 을 부르면 차례로 돈다.
  • 사용:
let mut action: Action<WorldNode> = Action::new()
    .wait(1.0, ActionCallbacks::new().updated(|progress, node: &mut WorldNode| node.set_local_opacity(progress)))
    .condition(|node: &WorldNode| node.is_active(), ActionConditionCallbacks::new())
    .call(|node: &mut WorldNode| node.set_local_scale(Vector2::create(2.0, 2.0)))
    .repeat(3, Action::new().wait(0.5, ActionCallbacks::new()))
    .forever(Action::new().wait(2.0, ActionCallbacks::new()));
action.start(&mut node_tree, Some(node_id));
// 매 프레임:
action.step(&mut node_tree, time_delta);
  • 원본과 다른 점:
  • 원본 start(target) 는 대상을 들고 있다가 step(timeDelta) 마다 콜백에 넘긴다. 러스트는 대상을 빌려 들 수 없어서 노드 대상은 핸들로 든다: start(트리, Some(노드)) 가 대상을 들고 step(트리, 시간) 이 그 노드를 콜백에 넘기며, get_target 이 그 노드를 돌려주고 start(트리, None) 이 원본 start() 처럼 이전 대상으로 다시 시작한다.
  • 대상을 들지 않고 매번 넘기는 꼴은 두 엔진 다 start_with(대상), step_with(대상, 시간) 이다. (원본 startWith, stepWith) 노드가 아닌 대상(노드 여럿, 게임 상태)은 T 로 쓰고 이 꼴로 돌린다. (T 의 기본은 WorldNode) repeat, forever, loop 의 안쪽 액션도 두 엔진 다 이 꼴로 돌아 대상을 들지 않는다. (안쪽 액션의 get_target 은 그대로)
  • 콜백 객체({ started, updated, completed })는 wait 스텝이 ActionCallbacks(updated 가 (진행률, 대상)), condition 스텝이 ActionConditionCallbacks(updated 가 (대상))다. 원본은 한 객체 꼴에 인자 수만 다르지만, 러스트는 콜백의 인자 꼴을 타입으로 정해야 해서 둘로 나눴다.
  • 조건 반복은 두 엔진 모두 repeat_while 이다. (원본 repeatWhile, 예약어 loop 를 이름으로 쓰지 않는다)
  • call 스텝이 이어지면 원본은 재귀로, 러스트 판은 반복문으로 넘긴다. (결과는 같다)
  • 조건 함수는 원본처럼 대상을 받는다(러스트는 &T). wait 은 duration 이 0 이하이면 진행률 1 로 끝낸다. repeat 은 횟수가 0 이면 돌지 않고 넘어간다. (원본과 같다)

Action. (a script-style sequence that runs steps in order)

  • A port of the original animation/action.js. Stack wait / condition / call / repeat / forever / loop steps, then call step every frame after start and they run in order.
  • Usage:
let mut action: Action<WorldNode> = Action::new()
    .wait(1.0, ActionCallbacks::new().updated(|progress, node: &mut WorldNode| node.set_local_opacity(progress)))
    .condition(|node: &WorldNode| node.is_active(), ActionConditionCallbacks::new())
    .call(|node: &mut WorldNode| node.set_local_scale(Vector2::create(2.0, 2.0)))
    .repeat(3, Action::new().wait(0.5, ActionCallbacks::new()))
    .forever(Action::new().wait(2.0, ActionCallbacks::new()));
action.start(&mut node_tree, Some(node_id));
// every frame:
action.step(&mut node_tree, time_delta);
  • Differences from the original:
  • The original start(target) holds the target and passes it to callbacks on every step(timeDelta). Rust cannot hold a borrowed target, so a node target is held as a handle: start(tree, Some(node)) holds the target and step(tree, time) passes that node to the callbacks, get_target returns that node, and start(tree, None) restarts with the previous target like the original start().
  • The form that does not hold a target and passes it every time is start_with(target), step_with(target, time) in both engines. (original startWith, stepWith) Use T for a target that is not a node (several nodes, game state) and run it in this form. (the default of T is WorldNode) The inner actions of repeat, forever, and loop also run in this form in both engines and do not hold a target. (get_target of an inner action is unchanged)
  • Callback objects ({ started, updated, completed }): the wait step uses ActionCallbacks (updated takes (progress, target)), and the condition step uses ActionConditionCallbacks (updated takes (target)). The original is one object form that differs only in argument count, but Rust must fix the argument shape of a callback as a type, so it is split in two.
  • The conditional loop is repeat_while in both engines. (original repeatWhile; the reserved word loop is not used as a name)
  • When call steps follow one another, the original passes through recursion and the Rust version through a loop. (the result is the same)
  • The condition function receives the target like the original (&T in Rust). wait finishes with progress 1 if duration is 0 or less. repeat skips without running if the count is 0. (same as the original)

ActionCallbacksstruct traits Default

소스source

스텝 콜백 묶음. (원본 { started, updated, completed })

  • wait 스텝에 넘긴다. 빌더처럼 started, updated, completed 를 이어 부른다. 비워 둔 콜백은 부르지 않는다.

Step callback set. (the original { started, updated, completed })

  • Passed to a wait step. Chain started, updated and completed like a builder. Callbacks left empty are not called.
예제Examplewait 스텝의 시작, 진행률, 완료 콜백Start, progress and completion callbacks of a wait step
use vanilla::{Action, ActionCallbacks};

let mut record: Vec<f64> = Vec::new();
let mut action: Action<Vec<f64>> = Action::new()
	.wait(1.0, ActionCallbacks::new()
		.started(|record: &mut Vec<f64>| record.push(-1.0))
		.updated(|progress, record: &mut Vec<f64>| record.push(progress))
		.completed(|record: &mut Vec<f64>| record.push(2.0)));
action.start_with(&mut record);
action.step_with(&mut record, 0.5);
action.step_with(&mut record, 0.5);
assert_eq!(record, vec![-1.0, 0.5, 1.0, 2.0]);
assert!(action.is_done());
생성자constructorpub fn new() -> ActionCallbacks<T>#0.3.2 부터since 0.3.2소스source

생성. (모두 비어 있음, 원본 {})

Constructor. (all empty, the original {})

반환ReturnsActionCallbacks<T> 콜백이 하나도 없는 묶음.A set with no callbacks.

메서드methodpub fn started(mut self, callback: impl FnMut(&mut T) + 'static) -> ActionCallbacks<T>#0.3.2 부터since 0.3.2소스source

스텝 시작 때 부를 콜백. ((대상))

Callback called when the step starts. ((target))

callbackimpl FnMut(&mut T) + 'static
스텝이 시작될 때 한 번 부를 함수. (대상을 받는다) 이미 있던 시작 콜백은 바뀐다.Function called once when the step starts. (takes the target) Replaces any existing start callback.

반환ReturnsActionCallbacks<T> 시작 콜백을 넣은 묶음. (이어 부르기용)The set with the start callback added. (for chaining)

메서드methodpub fn updated(mut self, callback: impl FnMut(f64, &mut T) + 'static) -> ActionCallbacks<T>#0.3.2 부터since 0.3.2소스source

매 프레임 부를 콜백. ((진행률 0 ~ 1, 대상). condition 스텝은 진행률 0)

Callback called every frame. ((progress 0 ~ 1, target). progress is 0 for condition steps)

callbackimpl FnMut(f64, &mut T) + 'static
스텝이 도는 동안 step 마다 부를 함수. (진행률 0 ~ 1 과 대상을 받는다, 마지막 프레임은 1) 이미 있던 갱신 콜백은 바뀐다.Function called on every step while the step runs. (takes progress 0 ~ 1 and the target, 1 on the last frame) Replaces any existing update callback.

반환ReturnsActionCallbacks<T> 갱신 콜백을 넣은 묶음. (이어 부르기용)The set with the update callback added. (for chaining)

메서드methodpub fn completed(mut self, callback: impl FnMut(&mut T) + 'static) -> ActionCallbacks<T>#0.3.2 부터since 0.3.2소스source

스텝 완료 때 부를 콜백. ((대상))

Callback called when the step completes. ((target))

callbackimpl FnMut(&mut T) + 'static
스텝이 끝날 때 한 번 부를 함수. (마지막 갱신 콜백 바로 뒤, 대상을 받는다) 이미 있던 완료 콜백은 바뀐다.Function called once when the step ends. (right after the last update callback, takes the target) Replaces any existing completion callback.

반환ReturnsActionCallbacks<T> 완료 콜백을 넣은 묶음. (이어 부르기용)The set with the completion callback added. (for chaining)

ActionConditionCallbacksstruct traits Default

소스source

condition 스텝 콜백 묶음. (원본 { started, updated, completed }, updated 가 (대상)만 받는다)

  • condition 스텝에 넘긴다. 빌더처럼 이어 부르고, 비워 둔 콜백은 부르지 않는다.

Condition step callback set. (the original { started, updated, completed }, updated takes only (target))

  • Passed to a condition step. Chain like a builder; callbacks left empty are not called.
예제Example문이 열릴 때까지 기다린 프레임 세기Count the frames waited until the door opens
use vanilla::{Action, ActionConditionCallbacks};

struct Door {
	is_open: bool,
	waited_frame_count: u32,
	is_passed: bool,
}

let mut door = Door { is_open: false, waited_frame_count: 0, is_passed: false };
let mut action: Action<Door> = Action::new()
	.condition(|door: &Door| door.is_open, ActionConditionCallbacks::new()
		.updated(|door: &mut Door| door.waited_frame_count += 1)
		.completed(|door: &mut Door| door.is_passed = true));
action.start_with(&mut door);
action.step_with(&mut door, 0.016);
action.step_with(&mut door, 0.016);
assert!(!door.is_passed);
door.is_open = true;
action.step_with(&mut door, 0.016);
assert_eq!(door.waited_frame_count, 3);
assert!(door.is_passed);
assert!(action.is_done());
생성자constructorpub fn new() -> ActionConditionCallbacks<T>#0.4.0 부터since 0.4.0소스source

생성. (모두 비어 있음, 원본 {})

Constructor. (all empty, the original {})

반환ReturnsActionConditionCallbacks<T> 콜백이 하나도 없는 묶음.A set with no callbacks.

메서드methodpub fn started(mut self, callback: impl FnMut(&mut T) + 'static) -> ActionConditionCallbacks<T>#0.4.0 부터since 0.4.0소스source

스텝 시작 때 부를 콜백. ((대상))

Callback called when the step starts. ((target))

callbackimpl FnMut(&mut T) + 'static
스텝이 시작될 때 한 번 부를 함수. (대상을 받는다) 이미 있던 시작 콜백은 바뀐다.Function called once when the step starts. (takes the target) Replaces any existing start callback.

반환ReturnsActionConditionCallbacks<T> 시작 콜백을 넣은 묶음. (이어 부르기용)The set with the start callback added. (for chaining)

메서드methodpub fn updated(mut self, callback: impl FnMut(&mut T) + 'static) -> ActionConditionCallbacks<T>#0.4.0 부터since 0.4.0소스source

조건 충족 전 매 프레임 부를 콜백. ((대상))

Callback called every frame before the condition is met. ((target))

callbackimpl FnMut(&mut T) + 'static
step 마다 조건을 묻기 전에 부를 함수. (대상을 받는다, 조건이 참이 되는 프레임에도 한 번 부른다) 이미 있던 갱신 콜백은 바뀐다.Function called on every step before checking the condition. (takes the target, also called once on the frame the condition becomes true) Replaces any existing update callback.

반환ReturnsActionConditionCallbacks<T> 갱신 콜백을 넣은 묶음. (이어 부르기용)The set with the update callback added. (for chaining)

메서드methodpub fn completed(mut self, callback: impl FnMut(&mut T) + 'static) -> ActionConditionCallbacks<T>#0.4.0 부터since 0.4.0소스source

조건 충족 때 부를 콜백. ((대상))

Callback called when the condition is met. ((target))

callbackimpl FnMut(&mut T) + 'static
조건이 참이 된 프레임에 한 번 부를 함수. (대상을 받는다) 이미 있던 완료 콜백은 바뀐다.Function called once on the frame the condition becomes true. (takes the target) Replaces any existing completion callback.

반환ReturnsActionConditionCallbacks<T> 완료 콜백을 넣은 묶음. (이어 부르기용)The set with the completion callback added. (for chaining)

Actionstruct traits Default

짝Counterpart: vanilla.js Action소스source

액션.

  • 스텝을 빌더처럼 쌓고 start 뒤 매 프레임 step 을 부르면 차례로 돈다. (대상을 매번 넘기면 start_with, step_with) 대상 꼴 T 는 기본 WorldNode 이다.

Action.

  • Stack steps like a builder, and after start, calling step every frame runs them in order. (to pass the target every time, use start_with, step_with) The target type T defaults to WorldNode.
예제Example노드를 서서히 보이고, 활성인지 보고, 키운 뒤 반복 대기Fade in a node, check whether it is active, scale it up, then wait repeatedly
use vanilla::{Action, ActionCallbacks, ActionConditionCallbacks, Vector2, WorldNode};

let mut node = WorldNode::new("hero");
let mut action: Action<WorldNode> = Action::new()
	.wait(1.0, ActionCallbacks::new().updated(|progress, node: &mut WorldNode| node.set_local_opacity(progress)))
	.condition(|node: &WorldNode| node.is_active(), ActionConditionCallbacks::new())
	.call(|node: &mut WorldNode| node.set_local_scale(Vector2::create(2.0, 2.0)))
	.repeat(3, Action::new().wait(0.5, ActionCallbacks::new()))
	.forever(Action::new().wait(2.0, ActionCallbacks::new()));
action.start_with(&mut node);
action.step_with(&mut node, 0.5);
assert_eq!(node.get_local_opacity(), 0.5);
action.step_with(&mut node, 0.5);
assert_eq!(node.get_local_opacity(), 1.0);
action.step_with(&mut node, 0.0);
assert_eq!(node.get_local_scale(), Vector2::create(2.0, 2.0));
for _ in 0..10 {
	action.step_with(&mut node, 0.5);
}
assert!(action.is_running());
assert!(!action.is_done());
생성자constructorpub fn new() -> Action<T>#0.3.2 부터since 0.3.2소스source

생성. (스텝 없음, 멈춤)

Constructor. (no steps, stopped)

반환ReturnsAction<T> 스텝이 없고 돌지 않는 액션. (스텝 없이 start 하면 바로 끝난다)An action with no steps that is not running. (start without steps ends immediately)

짝Counterpart: vanilla.js Action.constructor

메서드methodpub fn wait(mut self, duration: f64, callbacks: ActionCallbacks<T>) -> Action<T>#0.3.2 부터since 0.3.2소스source

일정 시간 대기. (started(대상), updated(진행률 0 ~ 1, 대상) 매 프레임, completed(대상))

Waits for a set time. (started(target), updated(progress 0 ~ 1, target) every frame, completed(target))

durationf64
기다릴 시간. (초, step 에 넘긴 time_delta 를 더해 잰다) 0 이하이면 첫 step 에서 진행률 1 로 끝난다.Time to wait. (seconds, measured by adding the time_delta passed to step) If 0 or less, ends with progress 1 on the first step.
callbacksActionCallbacks<T>
시작, 갱신, 완료 콜백 묶음.Start, update and completion callback set.

반환ReturnsAction<T> wait 스텝을 끝에 더한 액션. (이어 부르기용)The action with a wait step appended. (for chaining)

짝Counterpart: vanilla.js Action.wait

메서드methodpub fn condition(mut self, condition_function: impl FnMut(&T) -> bool + 'static, callbacks: ActionConditionCallbacks<T>) -> Action<T>#0.3.2 부터since 0.3.2소스source

조건이 참이 될 때까지 대기. (started(대상), updated(대상) 조건 충족 전 매 프레임, completed(대상))

Waits until the condition becomes true. (started(target), updated(target) every frame before the condition is met, completed(target))

condition_functionimpl FnMut(&T) -> bool + 'static
대상을 받아 참이면 넘어가는 함수. (start 에서는 묻지 않고 step 마다 묻는다)Function that takes the target and moves on if true. (not checked in start, checked on every step)
callbacksActionConditionCallbacks<T>
시작, 갱신, 완료 콜백 묶음.Start, update and completion callback set.

반환ReturnsAction<T> condition 스텝을 끝에 더한 액션. (이어 부르기용)The action with a condition step appended. (for chaining)

짝Counterpart: vanilla.js Action.condition

메서드methodpub fn call(mut self, function: impl FnMut(&mut T) + 'static) -> Action<T>#0.3.2 부터since 0.3.2소스source

즉시 콜백 호출.

Calls a callback immediately.

functionimpl FnMut(&mut T) + 'static
이 스텝에 닿자마자 부를 함수. (대상을 받는다, 같은 프레임에 다음 스텝으로 넘어간다)Function called as soon as this step is reached. (takes the target, moves to the next step in the same frame)

반환ReturnsAction<T> call 스텝을 끝에 더한 액션. (이어 부르기용)The action with a call step appended. (for chaining)

짝Counterpart: vanilla.js Action.call

메서드methodpub fn repeat(mut self, times: u32, inner_action: Action<T>) -> Action<T>#0.3.2 부터since 0.3.2소스source

안쪽 액션을 times 번 반복. (0 이면 돌지 않고 넘어간다)

Repeats the inner action times times. (moves on without running if 0)

timesu32
반복 횟수. 0 이면 안쪽을 시작하지 않고 넘어간다.Repeat count. If 0, moves on without starting the inner action.
inner_actionAction<T>
반복할 액션. (끝날 때마다 처음부터 다시 start 한다)Action to repeat. (started again from the beginning each time it ends)

반환ReturnsAction<T> repeat 스텝을 끝에 더한 액션. (이어 부르기용)The action with a repeat step appended. (for chaining)

짝Counterpart: vanilla.js Action.repeat

예제Example0.5초 대기를 세 번Wait 0.5 seconds three times
use vanilla::{Action, ActionCallbacks};

let mut count: u32 = 0;
let inner_action: Action<u32> = Action::new().wait(0.5, ActionCallbacks::new().completed(|count: &mut u32| *count += 1));
let mut action: Action<u32> = Action::new().repeat(3, inner_action);
action.start_with(&mut count);
for _ in 0..3 {
	action.step_with(&mut count, 0.5);
}
assert_eq!(count, 3);
assert!(action.is_done());
메서드methodpub fn forever(mut self, inner_action: Action<T>) -> Action<T>#0.3.2 부터since 0.3.2소스source

안쪽 액션을 끝없이 반복.

Repeats the inner action forever.

inner_actionAction<T>
반복할 액션. (끝날 때마다 처음부터 다시 start 한다)Action to repeat. (started again from the beginning each time it ends)

반환ReturnsAction<T> forever 스텝을 끝에 더한 액션. (이어 부르기용, 이 뒤의 스텝에는 닿지 않는다. 멈추려면 stop)The action with a forever step appended. (for chaining, steps after this are never reached. Use stop to halt)

짝Counterpart: vanilla.js Action.forever

메서드methodpub fn repeat_while(mut self, condition_function: impl FnMut(&T) -> bool + 'static, inner_action: Action<T>) -> Action<T>#0.4.0 부터since 0.4.0소스source

조건이 참인 동안 안쪽 액션을 반복. (시작할 때와 안쪽이 끝날 때마다 묻는다)

Repeats the inner action while the condition is true. (asks at the start and each time the inner one finishes)

condition_functionimpl FnMut(&T) -> bool + 'static
대상을 받아 참이면 안쪽을 (다시) 돌리는 함수. 처음부터 거짓이면 안쪽을 건너뛴다.Function that takes the target and runs the inner action (again) if true. If false from the start, the inner action is skipped.
inner_actionAction<T>
반복할 액션.Action to repeat.

반환ReturnsAction<T> loop 스텝을 끝에 더한 액션. (이어 부르기용)The action with a loop step appended. (for chaining)

짝Counterpart: vanilla.js Action.repeatWhile

예제Example값이 3 이 될 때까지 0.1초마다 하나씩 올리기Raise a value by one every 0.1 seconds until it reaches 3
use vanilla::{Action, ActionCallbacks};

let mut count: u32 = 0;
let inner_action: Action<u32> = Action::new().wait(0.1, ActionCallbacks::new().completed(|count: &mut u32| *count += 1));
let mut action: Action<u32> = Action::new().repeat_while(|count: &u32| *count < 3, inner_action);
action.start_with(&mut count);
for _ in 0..10 {
	action.step_with(&mut count, 0.1);
}
assert_eq!(count, 3);
assert!(action.is_done());
메서드methodpub fn start_with(&mut self, target: &mut T)#0.4.0 부터since 0.4.0소스source

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

  • 앞에 있는 call 스텝은 이 자리에서 바로 돈다. 돌던 중이면 처음부터 다시 한다. 대상은 들지 않는다. (get_target 은 그대로)

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

  • Leading call steps run right here. If it was running, it starts over. The target is not held. (get_target stays as it was)
target&mut T
콜백에 넘길 대상. (첫 스텝의 시작 콜백까지 이 자리에서 부른다)Target passed to the callbacks. (calls up to the first step's start callback right here)

짝Counterpart: vanilla.js Action.startWith

메서드methodpub fn stop(&mut self)#0.3.2 부터since 0.3.2소스source

실행 중단. (끝난 것으로 친다)

Stops running. (counts as finished)

짝Counterpart: vanilla.js Action.stop

메서드methodpub fn step_with(&mut self, target: &mut T, time_delta: f64)#0.4.0 부터since 0.4.0소스source

대상을 넘겨 갱신. (원본 stepWith(target, timeDelta), 매 프레임 호출)

  • start 전이거나 끝났으면 아무것도 하지 않는다. 한 번에 스텝 하나만 진행하고, 끝난 스텝 뒤의 call 스텝은 같은 프레임에 돈다.

Updates with a given target. (the original stepWith(target, timeDelta), call every frame)

  • Does nothing before start or after it is done. Advances only one step at a time, and call steps after a finished step run in the same frame.
target&mut T
콜백에 넘길 대상.Target passed to the callbacks.
time_deltaf64
지난 프레임에서 흐른 시간. (초, wait 스텝이 이것을 더해 잰다)Time elapsed since the last frame. (seconds, wait steps add this up)

짝Counterpart: vanilla.js Action.stepWith

예제Example씬 tick 에서 액션 돌리기Run an action in the scene tick
use vanilla::{Action, ActionCallbacks, WorldNode};

struct FadeIn {
	node: WorldNode,
	action: Action,
}

impl FadeIn {
	fn new() -> FadeIn {
		let mut fade_in = FadeIn {
			node: WorldNode::new("logo"),
			action: Action::new().wait(2.0, ActionCallbacks::new().updated(|progress, node: &mut WorldNode| node.set_local_opacity(progress))),
		};
		fade_in.action.start_with(&mut fade_in.node);
		fade_in
	}

	fn tick(&mut self, time_delta: f64) {
		self.action.step_with(&mut self.node, time_delta);
	}
}

let mut fade_in = FadeIn::new();
fade_in.tick(1.0);
assert_eq!(fade_in.node.get_local_opacity(), 0.5);
fade_in.tick(1.0);
assert!(fade_in.action.is_done());
메서드methodpub fn is_done(&self) -> bool#0.3.2 부터since 0.3.2소스source

완료 여부 반환.

Returns whether it is complete.

반환Returnsbool 마지막 스텝까지 끝났거나 stop 했으면 true. (start 전에는 false, forever 는 stop 전까지 false)true if every step has finished or stop was called. (false before start, false for forever until stop)

짝Counterpart: vanilla.js Action.isDone

메서드methodpub fn is_running(&self) -> bool#0.3.2 부터since 0.3.2소스source

실행 중 여부 반환.

Returns whether it is running.

반환Returnsbool start 뒤 아직 끝나지 않았으면 true.true if started and not yet finished.

짝Counterpart: vanilla.js Action.isRunning

메서드methodpub fn start(&mut self, node_tree: &mut NodeTree, node_id: Option<NodeId>) -> bool#0.3.2 부터since 0.3.2소스source

노드를 대상으로 실행 시작. (원본 start(target), 처음 스텝부터)

  • 대상을 노드 핸들로 들어, step 이 그 노드를 콜백에 넘기고 get_target 이 돌려준다.
  • node_id 가 None 이면 원본처럼 이전 대상(앞서 start 에 넘긴 노드)으로 다시 시작한다.

Starts running with a node as the target. (the original start(target), from the first step)

  • Holds the target as a node handle, so step passes that node to the callbacks and get_target returns it.
  • If node_id is None, restarts with the previous target (the node given to start before) like the original.
node_tree&mut NodeTree
대상 노드가 든 트리.The tree that holds the target node.
node_idOption<NodeId>
대상 노드. (None 이면 이전 대상)The target node. (None means the previous target)

반환Returnsbool 시작했으면 true. 대상이 없거나 그 노드가 지워졌으면 false. (그때는 시작하지 않는다)true if it started. false if there is no target or that node was removed. (it does not start then)

짝Counterpart: vanilla.js Action.start

예제Example노드 대상으로 돌리고, 대상을 안 주고 다시 시작하기Run with a node target, then restart without giving a target
use vanilla::{Action, ActionCallbacks, NodeTree, WorldNode};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let logo_id = node_tree.create_child(root_id, "logo");
let mut action: Action = Action::new().wait(2.0, ActionCallbacks::new().updated(|progress, node: &mut WorldNode| node.set_local_opacity(progress)));
assert!(action.start(&mut node_tree, Some(logo_id)));
assert_eq!(action.get_target(), Some(logo_id));
action.step(&mut node_tree, 1.0);
assert_eq!(node_tree[logo_id].get_local_opacity(), 0.5);

assert!(action.start(&mut node_tree, None));
action.step(&mut node_tree, 0.5);
assert_eq!(node_tree[logo_id].get_local_opacity(), 0.25);
메서드methodpub fn step(&mut self, node_tree: &mut NodeTree, time_delta: f64)#0.3.2 부터since 0.3.2소스source

대상 노드로 갱신. (원본 step(timeDelta), 매 프레임 호출)

  • start 로 넘긴 노드를 콜백에 넘긴다. 대상이 없거나 그 노드가 지워졌으면 아무것도 하지 않는다.

Updates with the target node. (the original step(timeDelta), call every frame)

  • Passes the node given to start to the callbacks. Does nothing if there is no target or that node was removed.
node_tree&mut NodeTree
대상 노드가 든 트리.The tree that holds the target node.
time_deltaf64
지난 프레임에서 흐른 시간. (초)Time elapsed since the last frame. (seconds)

짝Counterpart: vanilla.js Action.step

메서드methodpub fn get_target(&self) -> Option<NodeId>#0.4.0 부터since 0.4.0소스source

대상 반환. (원본 getTarget)

Returns the target. (the original getTarget)

반환ReturnsOption<NodeId> start 에 넘긴 대상 노드. 없으면 None. (start_with(&mut 노드) 로 빌려 준 대상은 들지 않는다)The target node given to start. None if there is none. (a target lent with start_with(&mut node) is not held)

짝Counterpart: vanilla.js Action.getTarget