vanilladocs
vanillapunch.com
API / base/timer

base/timer

쿨다운.

Cooldown.

Cooldownextends Object

짝Counterpart: vanilla-engine Cooldown

쿨다운.

  • "timer -= dt; if (timer <= 0) ..." 를 매번 손으로 쓰던 것을 표준화했다.
  • activate() 로 발동하면 지정한 시간 동안 isReady() 가 거짓이 된다.

Cooldown.

  • Standardizes the "timer -= dt; if (timer <= 0) ..." that was written by hand every time.
  • When triggered with use(), isReady() becomes false for the specified time.
예제Example발동하고 시간이 지나 다시 준비되기Trigger and become ready again over time
import { Cooldown } from "./build/vanilla.js";

const cooldown = new Cooldown(0.5);
console.log(cooldown.activate(), cooldown.activate());
cooldown.tick(0.25);
console.log(cooldown.getRemainSeconds(), cooldown.getProgress());
cooldown.tick(0.25);
console.log(cooldown.isReady());
생성자constructorconstructor(duration = 1)#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

durationnumber
쿨다운 시간. (초)Cooldown time. (seconds)

짝Counterpart: vanilla-engine Cooldown.new

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

갱신.

Update.

timeDeltanumber
지난 프레임과의 간격. (초, 남은 시간에서 빼고 0 아래로는 내려가지 않는다)Interval since the last frame. (seconds, subtracted from the remaining time, which does not go below 0)

짝Counterpart: vanilla-engine Cooldown.tick

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

발동 가능 여부.

Whether it can be triggered.

반환Returnsboolean 남은 시간이 0 이하이면 참.True if the remaining time is 0 or less.

짝Counterpart: vanilla-engine Cooldown.is_ready

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

발동. (준비되어 있으면 쿨다운을 시작하고 참을 반환, 러스트 판 activate 와 같다)

Activates. (If ready, starts the cooldown and returns true, same as Rust activate)

반환Returnsboolean 발동했으면 참. (쿨다운 중이면 거짓, 남은 시간은 그대로)True if triggered. (false during cooldown, the remaining time is kept)

짝Counterpart: vanilla-engine Cooldown.activate

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

곧바로 준비 상태로 되돌리기.

Immediately returns to the ready state.

짝Counterpart: vanilla-engine Cooldown.reset

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

쿨다운 시간 설정.

Sets the cooldown time.

durationnumber
쿨다운 시간. (초, 0 보다 작으면 0, 진행 중인 남은 시간은 바꾸지 않는다)Cooldown time. (seconds, 0 if less than 0, does not change the remaining time in progress)

짝Counterpart: vanilla-engine Cooldown.set_duration

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

쿨다운 시간 반환.

Returns the cooldown time.

반환Returnsnumber 쿨다운 시간. (초)Cooldown time. (seconds)

짝Counterpart: vanilla-engine Cooldown.get_duration

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

남은 시간 반환.

Returns the remaining time.

반환Returnsnumber 다시 준비될 때까지 남은 시간. (초, 준비되었으면 0)Time left until ready again. (seconds, 0 if ready)

짝Counterpart: vanilla-engine Cooldown.get_remain_seconds

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

진행 비율 반환. (0 = 방금 발동, 1 = 준비 완료)

Returns the progress ratio. (0 = just triggered, 1 = ready)

반환Returnsnumber 0 ~ 1. (쿨다운 시간이 0 이면 1, 쿨다운 중에 시간을 줄이면 0 보다 작아질 수 있다)0 ~ 1. (1 if the cooldown time is 0, may go below 0 if the time is shortened during cooldown)

짝Counterpart: vanilla-engine Cooldown.get_progress

RepeatTimerextends Object

짝Counterpart: vanilla-engine RepeatTimer

반복 타이머.

  • 일정 간격마다 콜백을 부른다. 프레임이 길어져 여러 번 지나쳤으면 밀린 만큼 몰아서 부른다.

Repeating timer.

  • Calls the callback at every interval. If several intervals passed because a frame ran long, calls it for all the missed ones at once.
예제Example간격마다 콜백 부르기Call a callback at each interval
import { RepeatTimer } from "./build/vanilla.js";

let spawnCount = 0;
const repeatTimer = new RepeatTimer(0.5, () => {
	spawnCount += 1;
});
repeatTimer.tick(0.2);
repeatTimer.tick(1.1);
console.log(spawnCount);
repeatTimer.pause();
repeatTimer.tick(1);
console.log(spawnCount, repeatTimer.isRunning());
생성자constructorconstructor(interval = 1, elapsedEvent = null)#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

intervalnumber
간격. (초)Interval. (seconds)
elapsedEventFunction
간격마다 부르는 콜백.Callback called at every interval.

짝Counterpart: vanilla-engine RepeatTimer.new

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

갱신.

Update.

timeDeltanumber
지난 프레임과의 간격. (초, 멈춰 있으면 쌓지 않는다, 한 번에 간격을 여러 번 넘으면 그 수만큼 콜백을 부른다)Interval since the last frame. (seconds, not accumulated while stopped, the callback is called once per interval passed at a time)

짝Counterpart: vanilla-engine RepeatTimer.tick

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

시작.

Start.

짝Counterpart: vanilla-engine RepeatTimer.start

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

정지. (누적 시간도 비운다)

Stops. (also clears the accumulated time)

짝Counterpart: vanilla-engine RepeatTimer.stop

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

일시 정지.

Pauses.

짝Counterpart: vanilla-engine RepeatTimer.pause

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

간격 설정.

Sets the interval.

intervalnumber
간격. (초, 0.000001 보다 작으면 0.000001)Interval. (seconds, 0.000001 if less than 0.000001)

짝Counterpart: vanilla-engine RepeatTimer.set_interval

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

간격 반환.

Returns the interval.

반환Returnsnumber 간격. (초)Interval. (seconds)

짝Counterpart: vanilla-engine RepeatTimer.get_interval

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

콜백 설정.

Sets the callback.

elapsedEventFunction
간격마다 부르는 콜백. (인자 없음, null 이면 부르지 않는다)Callback called at each interval. (no arguments, not called if null)

짝Counterpart: vanilla-engine RepeatTimer.set_elapsed_event

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

동작 중 여부.

Whether it is running.

반환Returnsboolean 동작 중이면 참. (만들 때부터 동작한다)True if running. (runs from creation)

짝Counterpart: vanilla-engine RepeatTimer.is_running