ui/uiscene
UI 씬.
UI scene.
UISceneextends Scene
UI 씬.
- Scene 을 직접 상속받는 독립 베이스 씬.
- GameScene 과 동일한 공통 인프라 (개발자 도구 / 터치 라우팅 / 로딩 화면 / env() safe-area 인셋 / viewSize 자동 감지 / 캔버스 배경 클리어) 를 자체 보유.
- 자체 LayoutSolver 인스턴스를 보유. tick 마다 updateVariables 자동 호출.
- 자체 화면 가이드 UINode (screenNode) 를 보유. 좌상단 (0, 0) 고정 + 너비/높이를 편집 변수로 등록해 resize 시 suggestValue 로 갱신한다. (UIKit 의 UIWindow.bounds 와 같은 사상)
- safeAreaLayoutGuide UINode 를 별도로 보유. screenNode 에서 safeAreaInsets 만큼 안쪽으로 들어간 영역을 표현. (UIKit 의 UIView.safeAreaLayoutGuide 와 동일 사상) layout() 단계에서 env() 인셋이 자동으로 setSafeAreaInsets 에 반영된다.
- 트리에 추가된 UINode 들은 tick 시 자동으로 솔버에 부착된다.
UI scene.
- Standalone base scene that directly inherits Scene.
- Has its own common infrastructure identical to GameScene (developer tools / touch routing / loading screen / env() safe-area insets / automatic viewSize detection / canvas background clear).
- Has its own LayoutSolver instance. Calls updateVariables automatically every tick.
- Has its own screen guide UINode (screenNode). Fixed at top-left (0, 0), with width/height registered as edit variables and updated via suggestValue on resize. (same idea as UIKit's UIWindow.bounds)
- Has a separate safeAreaLayoutGuide UINode. Represents the area inset from screenNode by safeAreaInsets. (same idea as UIKit's UIView.safeAreaLayoutGuide) In the layout() phase, env() insets are automatically applied to setSafeAreaInsets.
- UINodes added to the tree are automatically attached to the solver on tick.
import { Engine, EngineConfiguration, UIScene, UINode, UILabel, Paint, Vector2, Color } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
this.setSceneBackgroundColor(new Color(0.08, 0.09, 0.12, 1));
}
initialize(engine) {
super.initialize(engine);
const headerNode = new UINode();
headerNode.setName("header");
const paint = headerNode.addComponent(Paint);
paint.setColor(new Color(0.2, 0.45, 0.85, 1));
const label = headerNode.addComponent(UILabel);
label.setText("Header");
label.setFontSize(20);
const root = this.getRoot();
root.addChild(headerNode);
const safeAreaGuide = this.getSafeAreaLayoutGuide();
const safeLeftAnchor = safeAreaGuide.leftAnchor;
const safeRightAnchor = safeAreaGuide.rightAnchor;
const safeTopAnchor = safeAreaGuide.topAnchor;
const headerLeftAnchor = headerNode.leftAnchor;
const headerRightAnchor = headerNode.rightAnchor;
const headerTopAnchor = headerNode.topAnchor;
const headerHeightAnchor = headerNode.heightAnchor;
const leftConstraint = headerLeftAnchor.equalTo(safeLeftAnchor.add(16));
const rightConstraint = headerRightAnchor.equalTo(safeRightAnchor.subtract(16));
const topConstraint = headerTopAnchor.equalTo(safeTopAnchor.add(16));
const heightConstraint = headerHeightAnchor.equalTo(56);
headerNode.addConstraint(leftConstraint);
headerNode.addConstraint(rightConstraint);
headerNode.addConstraint(topConstraint);
headerNode.addConstraint(heightConstraint);
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());ViewScaleMode 설정. 프로젝트별로 자유롭게 지정 가능.
- 디폴트는 ViewScaleMode.none. 엔진 기동 전 / 후 어디서든 호출 가능.
- 호출 시점에 엔진이 이미 attach 되어 있으면 즉시 viewManager 에 반영하고, 아니면 initialize() 에서 일괄 적용된다.
Sets the ViewScaleMode. Can be set freely per project.
- Default is ViewScaleMode.none. Can be called anywhere before / after engine startup.
- If the engine is already attached at call time, it is applied to viewManager immediately, otherwise it is applied all at once in initialize().
- viewScaleModestring
- 뷰 배율 모드. (ViewScaleMode 의 값, 기본 ViewScaleMode.none)View scale mode. (a ViewScaleMode value, default ViewScaleMode.none)
짝Counterpart: vanilla-engine UISceneBase.set_view_scale_mode
현재 ViewScaleMode 반환.
Returns the current ViewScaleMode.
반환Returnsstring 지금 뷰 배율 모드. (ViewScaleMode 의 값)The current view scale mode. (a ViewScaleMode value)
짝Counterpart: vanilla-engine UISceneBase.get_view_scale_mode
로딩 화면 중앙 이미지 URL 설정. (빈 문자열이면 이미지 없이 게이지만 노출)
Sets the loading screen center image URL. (shows only the gauge without an image if empty string)
- urlstring
- 로딩 화면 가운데에 그릴 그림 주소. (null 이나 빈 글이면 그림 없이 게이지만 그린다)URL of the image drawn at the center of the loading screen. (if null or empty, only the gauge is drawn)
짝Counterpart: vanilla-engine UISceneBase.set_loading_image_url
로딩 화면 최소 노출 시간 (ms) 설정.
Sets the loading screen minimum display time (ms).
- millisecondsnumber
- 로딩 화면을 보여 줄 가장 짧은 시간. (밀리초, 기본 3000, 화면을 누르면 바로 넘긴다)Minimum time to show the loading screen. (milliseconds, default 3000, skipped at once when the screen is pressed)
짝Counterpart: vanilla-engine UISceneBase.set_loading_min_duration_ms
import { Engine, EngineConfiguration, UIScene, ImageAsset, Vector2 } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingImageUrl("assets/icons/icon.png");
this.setLoadingMinDurationMs(500);
this.imageAsset = null;
}
async loadAssets() {
await super.loadAssets();
const imageAsset = new ImageAsset();
await imageAsset.load("examples/assets/spritesheet.png");
this.imageAsset = imageAsset;
}
initialize(engine) {
super.initialize(engine);
console.log("loaded", this.imageAsset.isLoaded());
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());생성. 솔버 / screenNode / safeAreaLayoutGuide 셋업.
Create. Sets up the solver / screenNode / safeAreaLayoutGuide.
비동기 로드.
- 자체 자산을 로드 (loadAssets) 한 뒤 최소 노출 시간을 보장한다.
- 화면 터치 시 즉시 단축. drawOnLoad 단계에서는 씬의 touchPress 가 호출된다는 보장이 없어 window 이벤트로 직접 캡처.
- 로드 완료 후 viewSize 를 솔버에 즉시 반영한다.
Asynchronous load.
- Loads its own assets (loadAssets), then guarantees the minimum display time.
- Shortened immediately on screen touch. In the drawOnLoad phase there is no guarantee that the scene's touchPress is called, so it captures directly via window events.
- After loading completes, applies viewSize to the solver immediately.
- engineEngine
- 엔진.Engine.
짝Counterpart: vanilla-engine UISceneBase.load
자산 로드 hook.
- 서브클래스가 오버라이드해서 자체 자산을 비동기 로드한다. super 호출 필수.
Asset loading hook.
- Subclasses override it to load their own assets asynchronously. Calling super is required.
짝Counterpart: vanilla-engine UIScene.load_assets
로딩 화면 출력. (엔진이 isLoaded() === false 인 동안 매 프레임 호출)
- 검은 배경 + 중앙 로딩 이미지 + 하단 게이지.
Draws the loading screen. (called every frame by the engine while isLoaded() === false)
- Black background + center loading image + bottom gauge.
- graphicGraphic
- 그래픽.Graphics.
짝Counterpart: vanilla-engine UISceneBase.draw_on_load
초기화. 개발자 도구 + 터치 레이캐스터 셋업.
Initialize. Sets up developer tools + touch raycaster.
- engineEngine
- 엔진.Engine.
짝Counterpart: vanilla-engine UISceneBase.initialize
화면 크기 변경됨.
Screen size changed.
- canvasNativeSizeVector2
- 캔버스의 실제 픽셀 크기.Actual pixel size of the canvas.
짝Counterpart: vanilla-engine UISceneBase.resize
레이아웃.
- viewSize 를 솔버에 suggest 하고, 뷰 매니저의 세이프 에어리어 인셋을 자체 safeAreaInsets 에 동기화.
- 변화가 있을 때만 setSafeAreaInsets 호출 (제약 재구축 비용 절감).
Layout.
- Suggests viewSize to the solver, and syncs the view manager's safe area insets to its own safeAreaInsets.
- Calls setSafeAreaInsets only when there is a change (saves constraint rebuild cost).
짝Counterpart: vanilla-engine UISceneBase.layout
세이프 에어리어 영역 계산. (뷰 좌표계)
- 뷰 매니저의 getSafeAreaInsets 를 따른다. (setSafeAreaOverride > URL ?safeArea= > env() 실측, setIgnoredSafeAreaSides 로 뺀 쪽은 0)
Calculates the safe area rect. (view coordinate system)
- Follows the view manager's getSafeAreaInsets. (setSafeAreaOverride > URL ?safeArea= > measured env(), sides excluded with setIgnoredSafeAreaSides are 0)
반환ReturnsRect 세이프 에어리어 영역. (뷰 좌표, 너비와 높이는 0 이상)Safe area rectangle. (view coordinates, width and height are 0 or more)
import { Engine, EngineConfiguration, UIScene, Vector2 } from "./build/vanilla.js";
const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(1280, 720);
const engine = new Engine(engineConfiguration);
engine.getViewManager().setSafeAreaOverride({ top: 40, right: 0, bottom: 20, left: 10 });
class MainScene extends UIScene {
initialize() {
super.initialize();
const safeAreaRect = this.computeSafeAreaRect();
console.log(safeAreaRect.position.x, safeAreaRect.position.y, safeAreaRect.size.x, safeAreaRect.size.y);
}
}
engine.run(new MainScene());주기적 갱신.
- viewSize 변화 감지 → layout 자동 호출. (모바일 주소창 토글로 100vh 가 동적으로 변하는 경우 등에서 resize 이벤트만으론 누락될 수 있어 매 tick 보정.)
- 트리 내 새로 추가된 UINode 들을 솔버에 자동 부착 후 솔버 한 번 풀이.
- DevTools tick.
Periodic update.
- Detects viewSize changes → calls layout automatically. (in cases such as 100vh changing dynamically when the mobile address bar toggles, resize events alone can miss it, so it is corrected every tick.)
- Automatically attaches UINodes newly added in the tree to the solver, then solves once.
- DevTools tick.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
짝Counterpart: vanilla-engine UISceneBase.tick
트리를 순회하며 솔버가 부착되지 않은 UINode 들을 본 씬의 솔버에 부착.
Traverses the tree and attaches UINodes with no solver attached to this scene's solver.
- nodeTransformNode
- 훑기 시작할 노드. (null 이나 undefined 면 아무것도 하지 않는다)Node to start walking from. (does nothing if null or undefined)
화면 가이드 UINode 의 너비/높이 값 제안.
Suggests width/height values for the screen guide UINode.
- sizeVector2
- 화면 가이드에 줄 너비와 높이. (뷰 단위)Width and height to give the screen guide. (view units)
짝Counterpart: vanilla-engine UISceneBase.suggest_screen_size
safeAreaInsets 반환. (UIKit 의 UIView.safeAreaInsets)
Returns safeAreaInsets. (UIKit's UIView.safeAreaInsets)
반환Returns{ top: number, left: number, bottom: number, right: number } 지금 세이프 에어리어 인셋의 사본. (뷰 단위)A copy of the current safe area insets. (view units)
짝Counterpart: vanilla-engine UISceneBase.get_safe_area_insets
safeAreaInsets 설정. (모바일 노치 / 홈 인디케이터 회피용 영역 정의)
- safeAreaLayoutGuide 의 4 개 제약을 즉시 갱신한다.
Sets safeAreaInsets. (defines the area for avoiding the mobile notch / home indicator)
- Immediately updates the 4 constraints of safeAreaLayoutGuide.
- insets{ top: number, left: number, bottom: number, right: number }
- 위, 왼쪽, 아래, 오른쪽 인셋. (뷰 단위)Top, left, bottom and right insets. (view units)
짝Counterpart: vanilla-engine UISceneBase.set_safe_area_insets
safeAreaLayoutGuide 의 4 개 제약 재구축.
- 기존 제약을 솔버에서 제거하고 현재 #safeAreaInsets 로 다시 구축 후 재등록.
Rebuilds the 4 constraints of safeAreaLayoutGuide.
- Removes the existing constraints from the solver, rebuilds them with the current #safeAreaInsets and re-registers them.
짝Counterpart: vanilla-engine UISceneBase.rebuild_safe_area_layout_guide_constraints
개발자 도구 반환. (initialize 전이거나 EngineConfiguration.useDevTools 가 꺼져 있으면 null)
Returns the developer tools. (null before initialize or when EngineConfiguration.useDevTools is off)
반환ReturnsDevTools | null 개발자 도구. (만들지 않았으면 null)Developer tools. (null if not created)
짝Counterpart: vanilla-engine UISceneBase.get_dev_tools
import { Engine, EngineConfiguration, UIScene, Vector2 } from "./build/vanilla.js";
const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(1280, 720);
engineConfiguration.useDevTools = false;
const engine = new Engine(engineConfiguration);
class MainScene extends UIScene {
initialize() {
super.initialize();
console.log(this.getDevTools() === null);
}
}
engine.run(new MainScene());디브툴이 입력을 가져가는 중인지 여부.
Whether DevTools is taking the input.
반환Returnsboolean 개발자 도구 패널이 보이고 포인터가 그 위에 있으면 참.True if the developer tools panel is visible and the pointer is over it.
짝Counterpart: vanilla-engine UISceneBase.is_dev_tools_capturing_input
터치 레이캐스터 반환. (터치 훅에서 노드로 넘기는 TouchRecognizer, 씬 기본 넘기기는 끄고 이것으로 넘긴다)
Returns the touch raycaster. (the TouchRecognizer that the touch hooks pass to nodes; the scene's default passing is turned off and this one is used)
반환ReturnsTouchRecognizer 터치 훅이 넘기는 TouchRecognizer. (initialize 전에는 undefined)The TouchRecognizer that the touch hooks pass to. (undefined before initialize)
touchPress.
- viewInputPositionVector2
- 누른 자리. (뷰 좌표)Press position. (view coordinates)
짝Counterpart: vanilla-engine UIScene.touch_press
touchMove.
- viewInputPositionVector2
- 옮긴 자리. (뷰 좌표)Moved position. (view coordinates)
짝Counterpart: vanilla-engine UIScene.touch_move
touchRelease.
- viewInputPositionVector2
- 뗀 자리. (뷰 좌표)Release position. (view coordinates)
짝Counterpart: vanilla-engine UIScene.touch_release
touchCancel.
- viewInputPositionVector2
- 취소된 때의 자리. (뷰 좌표)Position at cancel. (view coordinates)
짝Counterpart: vanilla-engine UIScene.touch_cancel
touchWheel.
- viewInputPositionVector2
- 휠을 굴린 자리. (뷰 좌표)Position where the wheel was rolled. (view coordinates)
- wheelDeltaVector2
- 이번 프레임에 쌓인 휠 양. (WheelEvent 의 deltaX, deltaY)Wheel amount accumulated this frame. (deltaX, deltaY of WheelEvent)
짝Counterpart: vanilla-engine UIScene.touch_wheel
preDraw. 캔버스 전체를 sceneBackgroundColor 로 칠한다 (세이프 에어리어 바깥 영역 포함).
preDraw. Fills the whole canvas with sceneBackgroundColor (including the area outside the safe area).
- graphicGraphic
- 그래픽.Graphics.
짝Counterpart: vanilla-engine UISceneBase.pre_draw
postDraw. DevTools 를 화면 위에 그린다.
postDraw. Draws DevTools over the screen.
- graphicGraphic
- 그래픽.Graphics.
짝Counterpart: vanilla-engine UISceneBase.post_draw
솔버 반환.
Returns the solver.
반환ReturnsLayoutSolver 이 씬의 레이아웃 솔버. (create 전이면 undefined)This scene's layout solver. (undefined before create)
짝Counterpart: vanilla-engine UISceneBase.get_solver
화면 가이드 UINode 반환.
- 트리에는 들어가지 않는 가이드 노드. left/top 은 0 고정, width/height 는 현재 viewSize 와 동기화된 편집 변수.
- 사용자가 자기 UINode 의 제약을 화면 기준으로 작성할 때 앵커 소스로 사용.
Returns the screen guide UINode.
- Guide node not placed in the tree. left/top are fixed at 0, width/height are edit variables synced with the current viewSize.
- Used as an anchor source when users write constraints for their UINodes relative to the screen.
반환ReturnsUINode 화면 가이드 UINode.Screen guide UINode.
짝Counterpart: vanilla-engine UISceneBase.get_screen_node
safeAreaLayoutGuide 반환. (UIKit 의 UIView.safeAreaLayoutGuide 와 동일 사상)
- screenNode 에서 safeAreaInsets 만큼 안쪽으로 들어간 가이드 UINode.
- 사용자가 자기 UINode 의 제약을 safeArea 기준으로 작성할 때 앵커 소스로 사용.
Returns safeAreaLayoutGuide. (same idea as UIKit's UIView.safeAreaLayoutGuide)
- Guide UINode inset from screenNode by safeAreaInsets.
- Used as an anchor source when users write constraints for their UINodes relative to the safeArea.
반환ReturnsUINode 세이프 에어리어 가이드 UINode.Safe area guide UINode.
짝Counterpart: vanilla-engine UISceneBase.get_safe_area_layout_guide