vanilladocs
vanillapunch.com
API / core/scene

core/scene

씬.

Scene.

Sceneextends Object

짝Counterpart: vanilla-engine 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()
  • 터치는 씬 꼴과 상관없이 노드의 위젯이 받는다. 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)
예제Example불러오고, 갱신하고, 그리고, 누름 받기Load, update, draw and receive presses
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());
생성자constructorconstructor()#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

짝Counterpart: vanilla-engine SceneBase.new

메서드methodcreate()#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

짝Counterpart: vanilla-engine Scene.create

메서드methodsetEngine(engine)#0.2.0 부터since 0.2.0소스source

엔진 설정. (SceneManager가 load() 이전에 호출하여 drawOnLoad에서 접근 가능하게 함)

Sets the engine. (called by SceneManager before load() so it is accessible in drawOnLoad)

engineEngine
이 씬을 불러온 엔진.The engine that loaded this scene.
메서드methodsetLoaded(isLoaded)#0.2.0 부터since 0.2.0소스source

로딩 완료 여부 설정. (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

메서드methodisLoaded()#0.2.0 부터since 0.2.0소스source

로딩 완료 여부 반환.

Returns whether loading is complete.

반환Returnsboolean 불러오기를 마쳤으면 참. (initialize 바로 앞에 참이 된다)True if loading has finished. (becomes true right before initialize)

짝Counterpart: vanilla-engine SceneBase.is_loaded

메서드methoddrawOnLoad(graphic)#0.2.0 부터since 0.2.0소스source

로딩 중 출력. (비동기 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

예제Example불러오는 동안 글 띄우기Show text while loading
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());
메서드methoddestroy()#0.0.8 부터since 0.0.8소스source

파괴.

Destroy.

짝Counterpart: vanilla-engine Scene.destroy

메서드methodasync load(engine)#0.0.8 부터since 0.0.8소스source

비동기 로딩.

Async loading.

engineEngine
씬을 불러오는 엔진.The engine loading the scene.

짝Counterpart: vanilla-engine Scene.load

메서드methodinitialize(engine)#0.0.8 부터since 0.0.8소스source

초기화.

Initialization.

engineEngine
씬을 불러온 엔진.The engine that loaded the scene.

짝Counterpart: vanilla-engine Scene.initialize

메서드methodfinalize(engine)#0.0.8 부터since 0.0.8소스source

종료처리.

Finalization.

engineEngine
씬을 내리는 엔진.The engine unloading the scene.

짝Counterpart: vanilla-engine Scene.finalize

메서드methodonPageProcessRestored()#0.2.0 부터since 0.2.0소스source

페이지 프로세스 파기 후 복원 감지 (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

메서드methodonPageVisibilityRestored()#0.2.0 부터since 0.2.0소스source

페이지 가시성 복원 감지 (백그라운드 → 포어그라운드). 엔진이 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

메서드methodasync unload(engine)#0.0.8 부터since 0.0.8소스source

비동기 로딩 해제.

Async unloading.

engineEngine
씬을 내리는 엔진.The engine unloading the scene.

짝Counterpart: vanilla-engine Scene.unload

메서드methodresize(canvasNativeSize)#0.0.8 부터since 0.0.8소스source

화면 크기 변경됨.

Screen size changed.

canvasNativeSizeVector2
바뀐 캔버스 요소의 크기. (CSS 픽셀)New size of the canvas element. (CSS pixels)

짝Counterpart: vanilla-engine Scene.resize

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

주기적 갱신.

Periodic update.

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

짝Counterpart: vanilla-engine SceneBase.tick

메서드methodpreDraw(graphic)#0.0.8 부터since 0.0.8소스source

이전 출력.

Pre-draw.

graphicGraphic
그릴 그래픽.Graphic to draw with.

짝Counterpart: vanilla-engine Scene.pre_draw

메서드methoddraw(graphic)#0.0.8 부터since 0.0.8소스source

출력.

Draw.

graphicGraphic
그릴 그래픽.Graphic to draw with.

짝Counterpart: vanilla-engine SceneBase.draw

메서드methodpostDraw(graphic)#0.0.8 부터since 0.0.8소스source

이후 출력.

Post-draw.

graphicGraphic
그릴 그래픽.Graphic to draw with.

짝Counterpart: vanilla-engine Scene.post_draw

메서드methoddrawGizmos(graphic)#0.0.11 부터since 0.0.11소스source

기즈모 출력.

Gizmo draw.

graphicGraphic
그릴 그래픽.Graphic to draw with.

짝Counterpart: vanilla-engine Scene.draw_gizmos

메서드methodtickTouch(timeDelta)#0.0.8 부터since 0.0.8소스source

터치 갱신.

Touch update.

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

짝Counterpart: vanilla-engine SceneBase.tick_touch

메서드methodtouchPress(viewInputPosition)#0.0.8 부터since 0.0.8소스source

터치 누름.

Touch press.

viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.

짝Counterpart: vanilla-engine Scene.touch_press

메서드methodtouchMove(viewInputPosition)#0.0.8 부터since 0.0.8소스source

터치 이동.

Touch move.

viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.

짝Counterpart: vanilla-engine Scene.touch_move

메서드methodtouchRelease(viewInputPosition)#0.0.8 부터since 0.0.8소스source

터치 뗌.

Touch release.

viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.

짝Counterpart: vanilla-engine Scene.touch_release

메서드methodtouchCancel(viewInputPosition)#0.1.0 부터since 0.1.0소스source

터치 취소됨.

Touch cancelled.

viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.

짝Counterpart: vanilla-engine Scene.touch_cancel

메서드methodtouchWheel(viewInputPosition, wheelDelta)#0.2.1 부터since 0.2.1소스source

마우스 휠.

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

메서드methodstartTween(tween)#0.0.8 부터since 0.0.8소스source

트윈 시작.

Starts a tween.

tweenTween
시작할 트윈. (이미 도는 트윈이면 아무것도 하지 않는다)Tween to start. (does nothing if it is already running)

짝Counterpart: vanilla-engine SceneBase.start_tween

예제Example노드를 0.5 초 동안 나타나게 하기Fade a node in over 0.5 seconds
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());
메서드methodstopTween(tween)#0.0.8 부터since 0.0.8소스source

트윈 중단.

Stops a tween.

tweenTween
멈출 트윈. (이 씬에서 돌지 않으면 아무것도 하지 않는다)Tween to stop. (does nothing if it is not running in this scene)

짝Counterpart: vanilla-engine SceneBase.stop_tween

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

도는 트윈 수 반환.

Returns the number of running tweens.

반환Returnsnumber 도는 트윈 수.Number of running tweens.

짝Counterpart: vanilla-engine SceneBase.get_tween_count

메서드methodstopAllTweens()#0.0.8 부터since 0.0.8소스source

모든 트윈 중단.

Stops all tweens.

짝Counterpart: vanilla-engine SceneBase.stop_all_tweens

메서드methodgetEngine()#0.0.8 부터since 0.0.8소스source

엔진 반환.

Returns the engine.

반환ReturnsEngine 이 씬을 불러온 엔진. (불러오기 전에는 undefined)The engine that loaded this scene. (undefined before loading)

짝Counterpart: vanilla-engine SceneBase.get_engine

메서드methodgetRoot()#0.0.8 부터since 0.0.8소스source

루트 노드 반환.

Returns the root node.

반환ReturnsWorldNode 루트 노드. (create 에서 만들고, 크기는 뷰 크기)The root node. (created in create, sized to the view)

짝Counterpart: vanilla-engine SceneBase.get_root

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

터치 레이캐스터 설정.

  • 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)
예제Example스크롤 칸 끌기 손짓까지 넘기기Passing scroll view drag gestures too
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());
메서드methodsetTouchDispatchEnabled(isEnabled)#0.4.0 부터since 0.4.0소스source

노드에 터치 넘기기 켜고 끄기. (러스트 판 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

예제Example씬 기본 넘기기를 끄고 훅에서 직접 받기Turn off the scene's default passing and receive in the hooks directly
import { Scene } from "./build/vanilla.js";
const scene = new Scene();
scene.setTouchDispatchEnabled(false);
console.log(scene.isTouchDispatchEnabled()); // false
메서드methodisTouchDispatchEnabled()#0.4.0 부터since 0.4.0소스source

노드에 터치를 넘기는지 반환.

Returns whether touches are passed to nodes.

반환Returnsboolean 넘기면 참.true if it passes.

짝Counterpart: vanilla-engine SceneBase.is_touch_dispatch_enabled

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

터치 레이캐스터 반환.

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)

메서드methodsetGizmoVisible(isVisible)#0.0.9 부터since 0.0.9소스source

기즈모 그리기 설정.

Sets gizmo drawing.

isVisibleboolean
참이면 기즈모를 그린다.If true, gizmos are drawn.

짝Counterpart: vanilla-engine SceneBase.set_gizmo_visible

메서드methodisGizmoVisible()#0.0.9 부터since 0.0.9소스source

기즈모 그리기 여부 반환.

Returns whether gizmos are drawn.

반환Returnsboolean 기즈모를 그리면 참.True if gizmos are drawn.

짝Counterpart: vanilla-engine SceneBase.is_gizmo_visible

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

배경색 설정. (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

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

배경색 반환.

Returns the background color.

반환ReturnsColor 배경색. (기본 검정)Background color. (default black)

짝Counterpart: vanilla-engine SceneBase.get_scene_background_color

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

배경 그리기. (캔버스 전체를 배경색으로 칠하고 뷰 좌표계를 건다, 세이프 에어리어 바깥까지)

  • 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

예제ExampleScene 을 바로 이은 씬의 배경을 칠하기Filling the background of a scene that extends Scene directly
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());