ui/popupmotion
팝업 등장 / 퇴장 전환기.
Popup open / close transitioner.
PopupMotionextends Object
팝업 등장 / 퇴장 전환기.
- 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.
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();
}생성.
Constructor.
- optionsobject
- { openDuration = 0.32, closeDuration = 0.22 }
짝Counterpart: vanilla-engine PopupMotion.new
갱신.
Update.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
짝Counterpart: vanilla-engine PopupMotion.tick
현재 배율 반환.
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
어둡게 가리는 비율 반환. (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
조작 가능 여부. (완전히 열린 뒤에만 참)
Whether interactable. (true only after fully open)
반환Returnsboolean 열림 상태면 참.True if in the open state.
짝Counterpart: vanilla-engine PopupMotion.is_interactive
상태 조회.
State query.
반환Returnsstring 상태. (PopupMotionState 의 값)State. (a PopupMotionState value)
짝Counterpart: vanilla-engine PopupMotion.get_state
보이는지 반환. (닫힘이 아니면 참)
Returns whether it is visible. (true unless closed)
반환Returnsboolean 닫힘 상태가 아니면 참.True if not in the closed state.
짝Counterpart: vanilla-engine PopupMotion.is_visible
즉시 전환 여부 설정. (연출 없는 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
움직임 없이 바로 열고 닫는지.
Whether it opens and closes immediately without motion.
반환Returnsboolean 바로 열고 닫으면 참.True if it opens and closes immediately.
짝Counterpart: vanilla-engine PopupMotion.is_instant_enabled
알림 설정.
Sets the callback.
- openedEventFunction
- 다 열렸을 때 부를 함수. (인자 없음)Function to call when fully opened. (no arguments)
짝Counterpart: vanilla-engine PopupMotion.set_opened_event
다 닫혔을 때 알림 설정.
Sets the fully closed event.
- closedEventFunction
- 다 닫혔을 때 부를 함수. (인자 없음)Function to call when fully closed. (no arguments)
짝Counterpart: vanilla-engine PopupMotion.set_closed_event
PopupMotionStateenum
팝업 등장 / 퇴장 전환기.
- 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 |
|---|---|---|
closed | closed | 닫힘. (배율 0, 가림 0)Closed. (scale 0, dim 0) |
opening | opening | 여는 중. (배율이 0.45 에서 1.18 로 부풀었다가 1 로)Opening. (scale swells from 0.45 to 1.18 and settles at 1) |
open | open | 열림. (배율 1, 가림 1, 이때만 조작할 수 있다)Open. (scale 1, dim 1, the only state that accepts interaction) |
closing | closing | 닫는 중. (배율이 1.08 로 부풀었다가 0.08 로)Closing. (scale swells to 1.08 and shrinks to 0.08) |