core/scene
씬.
Scene.
Sceneextends Object
씬.
- new() ==> create() ==> async load(engine) ==> initialize(engine)
- finalize(engine) ==> async unload(engine) ==> destroy()
- resize(canvasNativeSize)
- tick(timeDelta)
- preDraw(graphic) ==> draw(graphic) ==> postDraw(graphic)
- touchPress(viewInputPosition) ==> touchMove(viewInputPosition) ==> touchRelease(viewInputPosition)
- reset()
- 터치는 씬 꼴과 상관없이 노드의 위젯이 받는다. tickTouch 가 씬의 터치 레이캐스터(처음은 TouchRaycaster, setTouchRaycaster 로 바꾼다)로 가장 앞의 누를 수 있는 노드에 먼저 넘기고, 그 뒤에 씬의 터치 훅을 부른다. (유니티 EventSystem 처럼, 러스트 판 SceneBase.tick 과 같다)
Scene.
- new() ==> create() ==> async load(engine) ==> initialize(engine)
- finalize(engine) ==> async unload(engine) ==> destroy()
- resize(canvasNativeSize)
- tick(timeDelta)
- preDraw(graphic) ==> draw(graphic) ==> postDraw(graphic)
- touchPress(viewInputPosition) ==> touchMove(viewInputPosition) ==> touchRelease(viewInputPosition)
- reset()
- Widgets on nodes receive touches whatever the kind of scene. tickTouch first passes the touch through the scene's touch raycaster (a TouchRaycaster at first, replaced with setTouchRaycaster) to the frontmost pressable node, then calls the scene's touch hooks. (like Unity's EventSystem, same as SceneBase.tick in the Rust version)
import { Engine, EngineConfiguration, Scene, Vector2, Rect, Colors } from "./build/vanilla.js";
class MainScene extends Scene {
async load(engine) {
await super.load(engine);
this.boxPosition = Vector2.create(100, 100);
}
initialize(engine) {
console.log("initialized");
}
tick(timeDelta) {
super.tick(timeDelta);
this.boxPosition.x += 60 * timeDelta;
}
draw(graphic) {
super.draw(graphic);
graphic.setFillColor(Colors.white);
graphic.drawRect(Rect.create(this.boxPosition.x, this.boxPosition.y, 80, 80));
}
touchPress(viewInputPosition) {
this.boxPosition = viewInputPosition.clone();
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());엔진 설정. (SceneManager가 load() 이전에 호출하여 drawOnLoad에서 접근 가능하게 함)
Sets the engine. (called by SceneManager before load() so it is accessible in drawOnLoad)
- engineEngine
- 이 씬을 불러온 엔진.The engine that loaded this scene.
로딩 완료 여부 설정. (SceneManager가 load+initialize 이후 true로 전환)
Sets whether loading is complete. (SceneManager switches it to true after load+initialize)
- isLoadedboolean
- 불러오기를 마쳤는지.Whether loading has finished.
짝Counterpart: vanilla-engine SceneBase.set_loaded
로딩 완료 여부 반환.
Returns whether loading is complete.
반환Returnsboolean 불러오기를 마쳤으면 참. (initialize 바로 앞에 참이 된다)True if loading has finished. (becomes true right before initialize)
짝Counterpart: vanilla-engine SceneBase.is_loaded
로딩 중 출력. (비동기 load() 진행 중에만 호출되며, 씬의 일반 tick/draw는 호출되지 않음)
Draws while loading. (called only while async load() is in progress, the scene's regular tick/draw is not called)
- graphicGraphic
- 그릴 그래픽.Graphic to draw with.
짝Counterpart: vanilla-engine Scene.draw_on_load
import { Engine, EngineConfiguration, Scene, Colors } from "./build/vanilla.js";
class MainScene extends Scene {
async load(engine) {
await super.load(engine);
await new Promise((resolve) => {
setTimeout(resolve, 500);
});
}
drawOnLoad(graphic) {
graphic.setFillColor(Colors.white);
graphic.setFontString("24px sans-serif");
graphic.drawFillText("Loading", 40, 40);
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());비동기 로딩.
Async loading.
- engineEngine
- 씬을 불러오는 엔진.The engine loading the scene.
짝Counterpart: vanilla-engine Scene.load
초기화.
Initialization.
- engineEngine
- 씬을 불러온 엔진.The engine that loaded the scene.
짝Counterpart: vanilla-engine Scene.initialize
종료처리.
Finalization.
- engineEngine
- 씬을 내리는 엔진.The engine unloading the scene.
짝Counterpart: vanilla-engine Scene.finalize
페이지 프로세스 파기 후 복원 감지 (freeze/resume, bfcache 복원 등). 엔진이 브라우저 이벤트를 감지하여 로드된 모든 씬에 호출한다.
Detects restoration after the page process was discarded (freeze/resume, bfcache restore, etc.). The engine detects the browser event and calls this on all loaded scenes.
짝Counterpart: vanilla-engine Scene.on_page_process_restored
페이지 가시성 복원 감지 (백그라운드 → 포어그라운드). 엔진이 visibilitychange 이벤트를 감지하여 로드된 모든 씬에 호출한다.
Detects page visibility restoration (background → foreground). The engine detects the visibilitychange event and calls this on all loaded scenes.
짝Counterpart: vanilla-engine Scene.on_page_visibility_restored
비동기 로딩 해제.
Async unloading.
- engineEngine
- 씬을 내리는 엔진.The engine unloading the scene.
짝Counterpart: vanilla-engine Scene.unload
화면 크기 변경됨.
Screen size changed.
- canvasNativeSizeVector2
- 바뀐 캔버스 요소의 크기. (CSS 픽셀)New size of the canvas element. (CSS pixels)
짝Counterpart: vanilla-engine Scene.resize
주기적 갱신.
Periodic update.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
짝Counterpart: vanilla-engine SceneBase.tick
이전 출력.
Pre-draw.
- graphicGraphic
- 그릴 그래픽.Graphic to draw with.
짝Counterpart: vanilla-engine Scene.pre_draw
이후 출력.
Post-draw.
- graphicGraphic
- 그릴 그래픽.Graphic to draw with.
짝Counterpart: vanilla-engine Scene.post_draw
기즈모 출력.
Gizmo draw.
- graphicGraphic
- 그릴 그래픽.Graphic to draw with.
짝Counterpart: vanilla-engine Scene.draw_gizmos
터치 갱신.
Touch update.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
짝Counterpart: vanilla-engine SceneBase.tick_touch
터치 누름.
Touch press.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
짝Counterpart: vanilla-engine Scene.touch_press
터치 이동.
Touch move.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
짝Counterpart: vanilla-engine Scene.touch_move
터치 뗌.
Touch release.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
짝Counterpart: vanilla-engine Scene.touch_release
터치 취소됨.
Touch cancelled.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
짝Counterpart: vanilla-engine Scene.touch_cancel
마우스 휠.
Mouse wheel.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
- wheelDeltaVector2
- 이번 프레임에 쌓인 휠 값. (WheelEvent 의 deltaX, deltaY 를 더한 것)Wheel amount accumulated this frame. (sum of WheelEvent deltaX, deltaY)
짝Counterpart: vanilla-engine Scene.touch_wheel
트윈 시작.
Starts a tween.
- tweenTween
- 시작할 트윈. (이미 도는 트윈이면 아무것도 하지 않는다)Tween to start. (does nothing if it is already running)
짝Counterpart: vanilla-engine SceneBase.start_tween
import { Engine, EngineConfiguration, Scene, WorldNode, Tween, TweenProperty, Vector2 } from "./build/vanilla.js";
class MainScene extends Scene {
initialize(engine) {
const root = this.getRoot();
const node = new WorldNode();
node.setContentSize(Vector2.create(100, 100));
root.addChild(node);
const tween = Tween.createNodeTween(node, TweenProperty.localOpacity, 0, 1, 0.5);
this.startTween(tween);
const tweenCount = this.getTweenCount();
console.log(tweenCount);
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());트윈 중단.
Stops a tween.
- tweenTween
- 멈출 트윈. (이 씬에서 돌지 않으면 아무것도 하지 않는다)Tween to stop. (does nothing if it is not running in this scene)
짝Counterpart: vanilla-engine SceneBase.stop_tween
도는 트윈 수 반환.
Returns the number of running tweens.
반환Returnsnumber 도는 트윈 수.Number of running tweens.
짝Counterpart: vanilla-engine SceneBase.get_tween_count
모든 트윈 중단.
Stops all tweens.
짝Counterpart: vanilla-engine SceneBase.stop_all_tweens
엔진 반환.
Returns the engine.
반환ReturnsEngine 이 씬을 불러온 엔진. (불러오기 전에는 undefined)The engine that loaded this scene. (undefined before loading)
짝Counterpart: vanilla-engine SceneBase.get_engine
루트 노드 반환.
Returns the root node.
반환ReturnsWorldNode 루트 노드. (create 에서 만들고, 크기는 뷰 크기)The root node. (created in create, sized to the view)
짝Counterpart: vanilla-engine SceneBase.get_root
터치 레이캐스터 설정.
- tickTouch 가 이 레이캐스터로 가장 앞의 누를 수 있는 노드에 터치를 넘긴다. 루트는 씬 루트로 건다.
- TouchRecognizer 를 주면 스크롤 칸 안의 끌기 손짓(누름 늦추기, 끌면 스크롤 칸으로)도 넘긴다.
- null 이면 노드에 넘기지 않는다. (씬이 터치 훅에서 직접 넘길 때, UIScene 과 GameScene 이 그렇게 한다)
Sets the touch raycaster.
- tickTouch passes touches to the frontmost pressable node through this raycaster. Its root is set to the scene root.
- Given a TouchRecognizer, drag gestures inside scroll views (delayed press, a drag goes to the scroll view) are passed too.
- null means touches are not passed to nodes. (when the scene passes them itself from its touch hooks, as UIScene and GameScene do)
- touchRaycasterTouchRaycaster | null
- 노드에 터치를 넘길 레이캐스터. (null 이면 넘기지 않는다)Raycaster that passes touches to nodes. (null means touches are not passed)
import { Engine, EngineConfiguration, Scene, TouchRecognizer } from "./build/vanilla.js";
class MainScene extends Scene {
initialize(engine) {
this.setTouchRaycaster(new TouchRecognizer());
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());노드에 터치 넘기기 켜고 끄기. (러스트 판 SceneBase.set_touch_dispatch_enabled 와 같다)
- 끄면 tickTouch 가 레이캐스터로 노드에 넘기지 않고 씬의 터치 훅만 부른다. (훅에서 가로채 직접 넘길 때)
- 레이캐스터는 그대로 두어 다시 켜면 이어서 넘긴다. setTouchRaycaster(null) 과 같은 효과다.
Turns passing touches to nodes on or off. (same as the Rust SceneBase.set_touch_dispatch_enabled)
- When off, tickTouch does not pass to nodes through the raycaster and only calls the scene's touch hooks. (for intercepting in the hooks and passing directly)
- The raycaster is kept, so turning it back on resumes passing. Same effect as setTouchRaycaster(null).
- isEnabledboolean
- 노드에 넘기면 참. (기본 참)true to pass to nodes. (true by default)
짝Counterpart: vanilla-engine SceneBase.set_touch_dispatch_enabled
import { Scene } from "./build/vanilla.js";
const scene = new Scene();
scene.setTouchDispatchEnabled(false);
console.log(scene.isTouchDispatchEnabled()); // false노드에 터치를 넘기는지 반환.
Returns whether touches are passed to nodes.
반환Returnsboolean 넘기면 참.true if it passes.
짝Counterpart: vanilla-engine SceneBase.is_touch_dispatch_enabled
터치 레이캐스터 반환.
Returns the touch raycaster.
반환ReturnsTouchRaycaster | null 노드에 터치를 넘기는 레이캐스터. (create 에서 TouchRaycaster 를 만든다, 넘기지 않으면 null)The raycaster that passes touches to nodes. (create makes a TouchRaycaster, null if touches are not passed)
기즈모 그리기 설정.
Sets gizmo drawing.
- isVisibleboolean
- 참이면 기즈모를 그린다.If true, gizmos are drawn.
짝Counterpart: vanilla-engine SceneBase.set_gizmo_visible
기즈모 그리기 여부 반환.
Returns whether gizmos are drawn.
반환Returnsboolean 기즈모를 그리면 참.True if gizmos are drawn.
짝Counterpart: vanilla-engine SceneBase.is_gizmo_visible
배경색 설정. (drawSceneBackground 가 칠한다, Color 나 "#202020" 같은 색 글)
Sets the background color. (drawSceneBackground fills it, a Color or color text such as "#202020")
- colorColor | string
- 배경색. (색 글은 Color.from 으로 읽는다, 기본 검정)Background color. (Color text is read with Color.from, default black)
짝Counterpart: vanilla-engine SceneBase.set_scene_background_color
배경색 반환.
Returns the background color.
반환ReturnsColor 배경색. (기본 검정)Background color. (default black)
짝Counterpart: vanilla-engine SceneBase.get_scene_background_color
배경 그리기. (캔버스 전체를 배경색으로 칠하고 뷰 좌표계를 건다, 세이프 에어리어 바깥까지)
- GameScene 과 UIScene 은 preDraw 에서 부른다. Scene 을 바로 잇는 씬은 preDraw 에서 불러 쓴다.
Draws the background. (Fills the whole canvas with the background color, including outside the safe area, and applies the view coordinate system)
- GameScene and UIScene call it in preDraw. A scene that extends Scene directly calls it in its own preDraw.
- graphicGraphic
- 그릴 그래픽.Graphic to draw with.
짝Counterpart: vanilla-engine SceneBase.draw_scene_background
import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
class MainScene extends Scene {
create() {
super.create();
this.setSceneBackgroundColor("#203040");
}
preDraw(graphic) {
super.preDraw(graphic);
this.drawSceneBackground(graphic);
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(1280, 720);
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());