vanilladocs
vanillapunch.com
API / ui/popupmotion

ui/popupmotion

팝업 등장 / 퇴장 전환기.

Popup open / close transitioner.

PopupMotionextends Object

짝Counterpart: vanilla-engine PopupMotion

팝업 등장 / 퇴장 전환기.

  • closed → opening → open → closing → closed 네 상태를 오가며 배율(등장: 0.45 → 1.18 되튕김 → 1, 퇴장: 1 → 1.08 → 0.08)과 어둡게 가리는 비율(dimRatio)을 산출한다. (여러 게임이 복붙하던 연출)
  • 렌더 방식과 무관하다. 매 프레임 tick(dt) 후 getScale() / getDimRatio() 를 읽어 노드 배율 / 막 알파에 적용한다. setInstantEnabled(true) 면 연출 없이 즉시 전환한다.

Popup open / close transitioner.

  • Cycles through four states closed → opening → open → closing → closed and computes the scale (open: 0.45 → 1.18 overshoot → 1, close: 1 → 1.08 → 0.08) and the dimming ratio (dimRatio). (an effect several games copy-pasted)
  • Independent of the rendering method. After tick(dt) every frame, read getScale() / getDimRatio() and apply them to node scale / backdrop alpha. With setInstantEnabled(true), switches immediately without the effect.
예제Example판의 배율과 막의 알파에 걸기Applying it to the panel scale and the dim alpha
import { PopupMotion, PopupMotionState, WorldNode, Paint, Color, Vector2 } from "./build/vanilla.js";

const panelNode = new WorldNode();
const dimNode = new WorldNode();
const dimPaint = dimNode.addComponent(Paint);
const popupMotion = new PopupMotion({ openDuration: 0.3, closeDuration: 0.2 });
popupMotion.setOpenedEvent(() => {
	console.log("opened");
});
popupMotion.setClosedEvent(() => {
	console.log("closed");
});
const applyMotion = () => {
	const scale = popupMotion.getScale();
	const dimRatio = popupMotion.getDimRatio();
	panelNode.setLocalScale(Vector2.create(scale, scale));
	dimPaint.setColor(new Color(0, 0, 0, 0.5 * dimRatio));
};
popupMotion.open();
for (let frameIndex = 0; frameIndex < 30; ++frameIndex) {
	popupMotion.tick(1 / 60);
	applyMotion();
}
const state = popupMotion.getState();
console.log(state === PopupMotionState.open);
popupMotion.close();
for (let frameIndex = 0; frameIndex < 30; ++frameIndex) {
	popupMotion.tick(1 / 60);
	applyMotion();
}
생성자constructorconstructor(options = {})#0.3.0 부터since 0.3.0소스source

생성.

Constructor.

optionsobject
{ openDuration = 0.32, closeDuration = 0.22 }

짝Counterpart: vanilla-engine PopupMotion.new

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

열기.

Open.

짝Counterpart: vanilla-engine PopupMotion.open

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

닫기.

Close.

짝Counterpart: vanilla-engine PopupMotion.close

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

갱신.

Update.

timeDeltanumber
지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)

짝Counterpart: vanilla-engine PopupMotion.tick

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

현재 배율 반환.

Returns the current scale.

반환Returnsnumber 판에 걸 배율. (닫힘 0, 열림 1, 여닫는 중에는 되튕김 곡선)Scale to apply to the panel. (0 when closed, 1 when open, a bounce curve while opening or closing)

짝Counterpart: vanilla-engine PopupMotion.get_scale

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

어둡게 가리는 비율 반환. (0 ~ 1)

Returns the dimming ratio. (0 ~ 1)

반환Returnsnumber 가리는 비율. (0 ~ 1, 여닫는 시간에 곧게 비례)Dim ratio. (0 ~ 1, linear in the open and close time)

짝Counterpart: vanilla-engine PopupMotion.get_dim_ratio

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

조작 가능 여부. (완전히 열린 뒤에만 참)

Whether interactable. (true only after fully open)

반환Returnsboolean 열림 상태면 참.True if in the open state.

짝Counterpart: vanilla-engine PopupMotion.is_interactive

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

상태 조회.

State query.

반환Returnsstring 상태. (PopupMotionState 의 값)State. (a PopupMotionState value)

짝Counterpart: vanilla-engine PopupMotion.get_state

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

보이는지 반환. (닫힘이 아니면 참)

Returns whether it is visible. (true unless closed)

반환Returnsboolean 닫힘 상태가 아니면 참.True if not in the closed state.

짝Counterpart: vanilla-engine PopupMotion.is_visible

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

즉시 전환 여부 설정. (연출 없는 UI 톤)

Sets whether to switch instantly. (UI tone without effects)

isInstantEnabledboolean
참이면 open, close 가 곧바로 열림, 닫힘이 되고 알림도 그 자리에서 부른다.If true, open and close switch to open and closed right away and also call the events on the spot.

짝Counterpart: vanilla-engine PopupMotion.set_instant_enabled

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

움직임 없이 바로 열고 닫는지.

Whether it opens and closes immediately without motion.

반환Returnsboolean 바로 열고 닫으면 참.True if it opens and closes immediately.

짝Counterpart: vanilla-engine PopupMotion.is_instant_enabled

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

알림 설정.

Sets the callback.

openedEventFunction
다 열렸을 때 부를 함수. (인자 없음)Function to call when fully opened. (no arguments)

짝Counterpart: vanilla-engine PopupMotion.set_opened_event

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

다 닫혔을 때 알림 설정.

Sets the fully closed event.

closedEventFunction
다 닫혔을 때 부를 함수. (인자 없음)Function to call when fully closed. (no arguments)

짝Counterpart: vanilla-engine PopupMotion.set_closed_event

PopupMotionStateenum

짝Counterpart: vanilla-engine PopupMotionState

팝업 등장 / 퇴장 전환기.

  • closed → opening → open → closing → closed 네 상태를 오가며 배율(등장: 0.45 → 1.18 되튕김 → 1, 퇴장: 1 → 1.08 → 0.08)과 어둡게 가리는 비율(dimRatio)을 산출한다. (여러 게임이 복붙하던 연출)
  • 렌더 방식과 무관하다. 매 프레임 tick(dt) 후 getScale() / getDimRatio() 를 읽어 노드 배율 / 막 알파에 적용한다. setInstantEnabled(true) 면 연출 없이 즉시 전환한다.

Popup open / close transitioner.

  • Cycles through four states closed → opening → open → closing → closed and computes the scale (open: 0.45 → 1.18 overshoot → 1, close: 1 → 1.08 → 0.08) and the dimming ratio (dimRatio). (an effect several games copy-pasted)
  • Independent of the rendering method. After tick(dt) every frame, read getScale() / getDimRatio() and apply them to node scale / backdrop alpha. With setInstantEnabled(true), switches immediately without the effect.
이름Name값Value설명Description
closedclosed닫힘. (배율 0, 가림 0)Closed. (scale 0, dim 0)
openingopening여는 중. (배율이 0.45 에서 1.18 로 부풀었다가 1 로)Opening. (scale swells from 0.45 to 1.18 and settles at 1)
openopen열림. (배율 1, 가림 1, 이때만 조작할 수 있다)Open. (scale 1, dim 1, the only state that accepts interaction)
closingclosing닫는 중. (배율이 1.08 로 부풀었다가 0.08 로)Closing. (scale swells to 1.08 and shrinks to 0.08)