vanilladocs
vanillapunch.com
API / core/node/worldnode

core/node/worldnode

계층적 영역 객체.

Hierarchical area object.

WorldNodeextends TransformNode

짝Counterpart: vanilla-engine WorldNode

계층적 영역 객체.

  • Anchor, Pivot, ConetentSize 기능.

Hierarchical area object.

  • Anchor, Pivot, ContentSize features.
예제Example부모 안에 사각형으로 놓고 맞는지 보기Place a rectangle inside a parent and test hits
import { WorldNode, Vector2 } from "./build/vanilla.js";

const panel = new WorldNode();
panel.setPivot(Vector2.create(0, 0));
panel.setContentSize(Vector2.create(400, 300));
const button = new WorldNode();
button.setRect(20, 20, 120, 40);
button.setInteractable(true);
panel.addChild(button);
const corners = button.getWorldCorners();
console.log(corners[0].x, corners[0].y, corners[2].x, corners[2].y);
const touchPosition = Vector2.create(50, 30);
const isInside = button.contains(touchPosition);
const localPosition = button.convertViewToLocal(touchPosition);
console.log(isInside, localPosition.x, localPosition.y);
생성자constructorconstructor()#0.1.0 부터since 0.1.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine NodeTree.new

메서드methodpushTransform(graphic)#0.1.0 부터since 0.1.0소스source

출력 상태 시작.

Begins the draw state.

graphicGraphic
변환을 걸 그래픽.Graphic to apply the transform to.

짝Counterpart: vanilla-engine WorldNode.push_transform

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

출력. (오버라이드: Mask 컴포넌트가 부착돼 있으면 자식을 그 영역으로 크롭)

Draw. (override: if a Mask component is attached, crops children to its area)

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

짝Counterpart: vanilla-engine NodeTree.draw

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

노드 스스로(컴포넌트와 자식 밖에) 그리는 사각형을 rect 에 적기. (내용 영역의 왼쪽 위가 원점, 알면 true)

  • draw 를 덮어쓰지 않은 노드는 스스로 그리는 것이 없으므로 크기 0 을 적고 true.
  • draw 를 덮어쓴 노드는 어디에 그리는지 모르므로 false. (그 노드의 조상은 하위 트리 그리기를 건너뛰지 않는다) 덮어쓴 노드가 이 함수도 덮어써 그리는 사각형을 알리면 건너뛸 수 있다. 사각형이 바뀌면 markDrawBoundsDirty 를 부른다.

Writes into rect the rectangle the node draws by itself (outside its components and children). (origin at the top-left of the content area, true if known)

  • A node that does not override draw draws nothing by itself, so it writes size 0 and returns true.
  • A node that overrides draw does not know where it draws and returns false. (its ancestors do not skip the subtree drawing) If the overriding node also overrides this function to report the drawn rectangle it can be skipped. Call markDrawBoundsDirty when the rectangle changes.
rectRect
그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)

반환Returnsboolean 알면 참.True if known.

예제Example스스로 그리는 노드가 그리는 곳 알리기Report where a self-drawing node draws
import { WorldNode, Rect, Vector2, Colors } from "./build/vanilla.js";

class Badge extends WorldNode {
	draw(graphic) {
		super.draw(graphic);
		const contentSize = this.getContentSize();
		graphic.setFillColor(Colors.white);
		graphic.drawRect(Rect.create(contentSize.x - 6, -6, 12, 12));
	}
	calculateDrawnRect(rect) {
		const contentSize = this.getContentSize();
		rect.position.set(contentSize.x - 6, -6);
		rect.size.set(12, 12);
		return true;
	}
}

const badge = new Badge();
badge.setContentSize(Vector2.create(40, 40));
const drawnRect = Rect.zero();
console.log(badge.calculateDrawnRect(drawnRect), drawnRect.position.x);
메서드methodtransformDrawBoundsToParent(rect)#0.4.0 부터since 0.4.0소스source

하위 트리 그리기 경계를 부모의 내용 좌표로 옮기기. (오버라이드: 위치, 회전, 배율, 피봇으로, pushTransform 과 같은 차례)

  • pushTransform 이나 위치, 배율, 회전, 피봇, 내용 크기 읽기를 덮어쓴 노드는 어디에 놓이는지 모르므로 false. (부모는 건너뛰지 않고 이 노드 아래는 저마다 건너뛸 수 있다)

Moves subtree draw bounds into the parent's content coordinates. (Override: by position, rotation, scale and pivot, in the same order as pushTransform)

  • A node that overrides pushTransform or the position, scale, rotation, pivot or content size getters has unknown placement and returns false. (The parent is not skipped; nodes below this one can still be skipped on their own)
rectRect
옮길 경계. (이 노드의 내용 좌표, 부모의 내용 좌표로 바뀐 경계 상자를 적는다)The bounds to move. (In this node's content coordinates; the bounding box in the parent's content coordinates is written back)

반환Returnsboolean 놓이는 곳을 알면 참.True if where the node is placed is known.

예제Example자식의 그리기 경계를 부모 좌표로 옮기기Moving a child's draw bounds into parent coordinates
import { WorldNode, Rect, Vector2, Pivot } from "./build/vanilla.js";

const node = new WorldNode();
node.setPivot(Pivot.topLeft);
node.setLocalPosition(Vector2.create(100, 20));
node.setLocalScale(Vector2.create(2, 2));
const drawBounds = Rect.create(0, 0, 10, 10);
node.transformDrawBoundsToParent(drawBounds);
console.log(drawBounds.position.x, drawBounds.size.x);
메서드methoddrawGizmos(graphic)#0.1.0 부터since 0.1.0소스source

출력.

Draw.

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

짝Counterpart: vanilla-engine WorldNode.draw_gizmos

메서드methodsetPivot(pivot)#0.1.0 부터since 0.1.0소스source

기준점 설정.

Sets the pivot.

pivotVector2
기준점. (내용 크기에 대한 비, 0 ~ 1 로 자르고, (0, 0) 이 왼쪽 위)Pivot. (ratio of the content size, clamped to 0 ~ 1, (0, 0) is the top-left)

짝Counterpart: vanilla-engine WorldNode.set_pivot

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

기준점 반환.

Returns the pivot.

반환ReturnsVector2 기준점의 사본.A copy of the pivot.

짝Counterpart: vanilla-engine WorldNode.get_pivot

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

기준점을 주어진 벡터에 쓰기. (getPivot 과 같은 값, 복제하지 않는다)

Writes the pivot into a given vector. (Same value as getPivot, no clone)

outVector2
쓸 벡터.Vector to write.

반환ReturnsVector2 out.

짝Counterpart: vanilla-engine WorldNode.read_pivot

예제Example기준점 읽기Read the pivot
import { WorldNode, Vector2 } from "./vanilla.js";
const node = new WorldNode();
node.setPivot(Vector2.create(0.5, 1));
const pivot = node.readPivot(Vector2.create(0, 0));
if (pivot.x !== 0.5 || pivot.y !== 1) {
	throw new Error("pivot failed");
}
메서드methodsetContentSize(contentSize)#0.1.0 부터since 0.1.0소스source

실제 내용 크기 설정.

Sets the actual content size.

contentSizeVector2
내용 크기. (값을 옮겨 적는다)Content size. (values are copied)

짝Counterpart: vanilla-engine WorldNode.set_content_size

메서드methodsetContentSizeXY(width, height)#0.4.0 부터since 0.4.0소스source

실제 내용 크기 설정. (너비, 높이를 바로 받는다, Vector2 를 만들지 않는다)

  • setContentSize() 를 덮어쓴 하위 클래스면 setContentSize 로 넘긴다.

Sets the actual content size. (takes width, height directly, does not create a Vector2)

  • Subclasses that override setContentSize() are forwarded to setContentSize.
widthnumber
내용 너비.Content width.
heightnumber
내용 높이.Content height.

짝Counterpart: vanilla-engine WorldNode.set_content_size_xy

메서드methodsetRect(x, y, width, height)#0.4.0 부터since 0.4.0소스source

부모 영역 안의 사각형에 놓기. (x, y 는 이 노드의 왼쪽 위, 부모 내용 영역의 왼쪽 위가 원점)

  • 내용 크기를 width, height 로 두고, 피봇이 어디든 왼쪽 위가 (x, y) 에 오게 로컬 위치를 정한다. (x + width * pivot.x, y + height * pivot.y)
  • 앵커는 바꾸지 않는다. 로컬 위치는 앵커와 무관하게 부모 왼쪽 위 기준이라 앵커가 어디든 같은 자리다. (getAnchoredPosition 은 그 앵커 기준으로 다시 셈해 준다)
  • 로컬 배율과 회전은 보지 않는다. (배율 1, 회전 0 일 때 화면에서도 그 사각형이다)

Places the node in a rectangle within the parent area. (x, y is this node's top-left, origin at the top-left of the parent content area)

  • Sets the content size to width, height and sets the local position so the top-left lands at (x, y) wherever the pivot is. (x + width * pivot.x, y + height * pivot.y)
  • Does not change the anchor. The local position is relative to the parent's top-left regardless of the anchor, so it is the same spot wherever the anchor is. (getAnchoredPosition recomputes it relative to that anchor)
  • Ignores local scale and rotation. (with scale 1 and rotation 0, it is that rectangle on screen too)
xnumber
왼쪽 위 X. (부모 내용 영역의 왼쪽 위가 원점)Top-left X. (origin at the top-left of the parent's content area)
ynumber
왼쪽 위 Y. (부모 내용 영역의 왼쪽 위가 원점)Top-left Y. (origin at the top-left of the parent's content area)
widthnumber
내용 너비.Content width.
heightnumber
내용 높이.Content height.

짝Counterpart: vanilla-engine WorldNode.set_rect

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

실제 내용 크기 반환.

  • 부모가 없고(루트 노드) 명시적으로 설정된 적 없으면 현재 뷰 크기를 반환한다.

Returns the actual content size.

  • If there is no parent (root node) and it was never set explicitly, returns the current view size.

반환ReturnsVector2 내용 크기의 사본.A copy of the content size.

짝Counterpart: vanilla-engine WorldNode.get_content_size

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

내용 크기를 주어진 벡터에 쓰기. (getContentSize 와 같은 값, 복제하지 않는다)

Writes the content size into a given vector. (Same value as getContentSize, no clone)

outVector2
쓸 벡터.Vector to write.

반환ReturnsVector2 out.

짝Counterpart: vanilla-engine WorldNode.read_content_size

예제Example내용 크기 읽기Read the content size
import { WorldNode, Vector2 } from "./vanilla.js";
const node = new WorldNode();
node.setContentSize(Vector2.create(120, 40));
const contentSize = node.readContentSize(Vector2.create(0, 0));
if (contentSize.x !== 120 || contentSize.y !== 40) {
	throw new Error("content size failed");
}
메서드methodcopyContentSizeTo(target)#0.4.0 부터since 0.4.0소스source

실제 내용 크기를 target 에 적는다. (복제본을 만들지 않는다, Paint 가 그릴 때마다 쓴다)

  • getContentSize() 를 덮어쓴 하위 클래스면 그 함수가 주는 값을 적는다.

Writes the actual content size into target. (does not create a copy, used by Paint on every draw)

  • Subclasses that override getContentSize() write the value that function returns.
targetVector2
내용 크기를 받을 벡터.Vector that receives the content size.

짝Counterpart: vanilla-engine WorldNode.copy_content_size_to

메서드methodsetAnchor(anchor)#0.1.0 부터since 0.1.0소스source

앵커 설정.

Sets the anchor.

anchorVector2
앵커. (부모 내용 크기에 대한 비, 0 ~ 1 로 자른다)Anchor. (ratio of the parent's content size, clamped to 0 ~ 1)

짝Counterpart: vanilla-engine WorldNode.set_anchor

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

앵커 반환.

Returns the anchor.

반환ReturnsVector2 앵커. (안의 벡터 그대로)The anchor. (the internal vector as is)

짝Counterpart: vanilla-engine WorldNode.get_anchor

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

앵커 기준 위치 설정.

  • anchoredPosition: 부모 영역 내 anchor 기준점(= parentContentSize * anchor)에서의 상대 위치.
  • 내부적으로 localPosition = anchorRef + anchoredPosition 으로 변환해 저장한다. (localPosition 은 anchor 와 무관하게 부모 영역 내 자기 중심점 좌표를 나타냄)

Sets the anchored position.

  • anchoredPosition: position relative to the anchor reference point (= parentContentSize * anchor) within the parent area.
  • Internally converted and stored as localPosition = anchorRef + anchoredPosition. (localPosition represents the coordinates of its own center point within the parent area regardless of anchor)
anchoredPositionVector2
앵커 기준 자리. (부모가 WorldNode 가 아니면 로컬 위치로 쓰고, null 이면 아무것도 하지 않는다)Position relative to the anchor. (used as the local position if the parent is not a WorldNode; does nothing if null)
예제Example부모의 오른쪽 위 귀퉁이에서 띄워 놓기Offset from the parent's top-right corner
import { WorldNode, Vector2 } from "./build/vanilla.js";

const parent = new WorldNode();
parent.setContentSize(Vector2.create(800, 600));
const closeButton = new WorldNode();
parent.addChild(closeButton);
closeButton.setAnchor(Vector2.create(1, 0));
closeButton.setAnchoredPosition(Vector2.create(-50, 40));
const localPosition = closeButton.getLocalPosition();
const anchoredPosition = closeButton.getAnchoredPosition();
console.log(localPosition.x, localPosition.y, anchoredPosition.x, anchoredPosition.y);
메서드methodgetAnchoredPosition()#0.2.0 부터since 0.2.0소스source

앵커 기준 위치 반환.

  • localPosition - anchorRef 로 역산해서 반환한다.

Returns the anchored position.

  • Computed back as localPosition - anchorRef.

반환ReturnsVector2 앵커 기준 자리. (부모가 WorldNode 가 아니면 로컬 위치)Position relative to the anchor. (the local position if the parent is not a WorldNode)

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

글로벌 위치 반환.

  • localPosition 은 부모 content top-left 기준 자기 객체 중심 좌표.
  • 부모의 pivot 점은 (parentContentSize * parentPivot) 위치이므로 parent.getPosition() (= 부모 pivot 점의 월드 좌표) 기준 오프셋으로 변환 후 부모 회전/스케일을 적용한다. (anchor 는 위치 계산에 직접 영향 없음)

Returns the global position.

  • localPosition is the object's own center coordinate relative to the parent content top-left.
  • The parent's pivot point is at (parentContentSize * parentPivot), so it is converted into an offset from parent.getPosition() (= world coordinates of the parent pivot point) and then the parent rotation/scale is applied. (anchor has no direct effect on the position calculation)

반환ReturnsVector2 월드 자리. (기준점의 자리)World position. (position of the pivot point)

짝Counterpart: vanilla-engine NodeTree.get_position

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

글로벌 위치를 주어진 벡터에 쓰기. (getPosition 과 같은 셈과 차례, 새 벡터를 짓지 않는다)

  • getPosition 이나 부모의 내용 크기, 기준점 읽기를 덮어쓴 하위 클래스면 그 함수로 읽는다.

Writes the global position into a given vector. (Same arithmetic in the same order as getPosition, no new vector)

  • Subclasses that override getPosition or the parent's content size or pivot readers are read through those functions.
outVector2
쓸 벡터.Vector to write.

반환ReturnsVector2 out. (기준점의 자리)out. (Position of the pivot)

짝Counterpart: vanilla-engine NodeTree.read_position

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

글로벌 위치 설정. (getPosition 의 거꾸로)

  • parent.getPosition() (= 부모 pivot 점의 월드 좌표) 에서 본 차이를 부모 회전/스케일을 풀어 부모 pivot 점 기준 오프셋으로 되돌린 뒤 부모 content top-left 기준(localPosition)으로 옮긴다. 부모 스케일이 0 인 축은 부모 pivot 점에 놓는다.

Sets the global position. (inverse of getPosition)

  • Takes the difference seen from parent.getPosition() (= world coordinates of the parent pivot point), undoes the parent rotation/scale to get back the offset from the parent pivot point, then moves it to the parent content top-left basis (localPosition). On axes where the parent scale is 0, it is placed at the parent pivot point.
positionVector2
월드 자리. (기준점의 자리, 부모의 회전과 배율을 풀어 로컬 위치로 바꾼다)World position. (position of the pivot point, converted to the local position by undoing the parent's rotation and scale)

짝Counterpart: vanilla-engine NodeTree.set_position

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

실제 화면에 그려지는 영역 반환. (OBB)

Returns the area actually drawn on screen. (OBB)

반환ReturnsVector2[] 네 귀퉁이. (왼쪽 위, 오른쪽 위, 오른쪽 아래, 왼쪽 아래 차례, 뷰 좌표)The four corners. (top-left, top-right, bottom-right, bottom-left, in view coordinates)

짝Counterpart: vanilla-engine NodeTree.get_world_corners

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

getWorldCorners()를 기반으로 최소, 최대위치를 만들어 바운딩박스를 형성.

Forms a bounding box from the min and max positions based on getWorldCorners().

반환ReturnsRect 네 귀퉁이를 감싸는 축 정렬 사각형.Axis-aligned rectangle enclosing the four corners.

짝Counterpart: vanilla-engine NodeTree.get_world_bounds

메서드methodcontains(viewPosition)#0.1.0 부터since 0.1.0소스source

getWorldCorners() 를 통한 충돌 검출.

Collision detection via getWorldCorners().

viewPositionVector2
볼 뷰 좌표.View coordinates to test.

반환Returnsboolean 네 귀퉁이 안이면 참. (null 이면 거짓)True if inside the four corners. (false if null)

짝Counterpart: vanilla-engine NodeTree.contains

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

뷰 좌표 → 이 노드의 로컬 좌표. (내용 영역의 왼쪽 위가 원점, 오른쪽 아래가 내용 크기)

  • 부모들의 위치, 배율, 회전을 모두 거친 네 귀퉁이(getWorldCorners)로 셈하므로 contains 와 같은 판정이다.
  • 내용 크기가 0 인 축은 0 을 돌려준다.

View coordinates → this node's local coordinates. (origin at the top-left of the content area, bottom-right is the content size)

  • Computed with the four corners (getWorldCorners) after all parents' position, scale and rotation, so it is the same test as contains.
  • Returns 0 on axes where the content size is 0.
viewPositionVector2
바꿀 뷰 좌표.View coordinates to convert.

반환ReturnsVector2 로컬 좌표. (내용 영역의 왼쪽 위가 원점)Local coordinates. (origin at the top-left of the content area)

짝Counterpart: vanilla-engine NodeTree.convert_view_to_local

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

노드 영역 안의 점 → 뷰 좌표. (내용 영역의 왼쪽 위가 원점, 부모들의 변환을 모두 거친다, 러스트 판 NodeTree::convert_node_position_to_view_position)

A point inside the node area → view coordinates. (The top left of the content area is the origin, goes through all parent transforms, Rust edition NodeTree::convert_node_position_to_view_position)

nodePositionVector2
이 노드 내용 좌표의 점.A point in this node's content coordinates.

반환ReturnsVector2 뷰 좌표의 점.A point in view coordinates.

짝Counterpart: vanilla-engine NodeTree.convert_node_position_to_view_position

예제Example단추 오른쪽 아래 귀퉁이의 뷰 자리View position of a button's bottom right corner
import { Vector2, WorldNode } from "./build/vanilla.js";

const rootNode = new WorldNode();
const buttonNode = new WorldNode();
rootNode.addChild(buttonNode);
buttonNode.setLocalPosition(Vector2.create(100, 100));
buttonNode.setContentSize(Vector2.create(40, 20));
const corner = buttonNode.convertNodePositionToViewPosition(Vector2.create(40, 20));
console.log(corner.x, corner.y);
메서드methodconvertViewPositionToNodePosition(viewPosition)#0.4.0 부터since 0.4.0소스source

뷰 좌표 → 노드 영역 안의 점. (행렬을 뒤집을 수 없으면(배율 0) null, 러스트 판 NodeTree::convert_view_position_to_node_position)

View coordinates → a point inside the node area. (null if the matrix cannot be inverted (scale 0), Rust edition NodeTree::convert_view_position_to_node_position)

viewPositionVector2
뷰 좌표의 점.A point in view coordinates.

반환ReturnsVector2 | null 이 노드 내용 좌표의 점. (배율이 0 이라 뒤집을 수 없으면 null)A point in this node's content coordinates. (null if the scale is 0 and it cannot be inverted)

짝Counterpart: vanilla-engine NodeTree.convert_view_position_to_node_position

예제Example뷰 자리를 노드 안 자리로 바꾸고 되돌리기Converting a view position to a position inside the node and back
import { Vector2, WorldNode } from "./build/vanilla.js";

const rootNode = new WorldNode();
const panelNode = new WorldNode();
rootNode.addChild(panelNode);
panelNode.setLocalPosition(Vector2.create(200, 100));
panelNode.setContentSize(Vector2.create(100, 50));
panelNode.setLocalScale(Vector2.create(2, 2));
const nodePosition = panelNode.convertViewPositionToNodePosition(Vector2.create(200, 100));
console.log(nodePosition.x, nodePosition.y);
panelNode.setLocalScale(Vector2.create(0, 1));
console.log(panelNode.convertViewPositionToNodePosition(Vector2.create(200, 100)));
메서드methodsetInteractable(isInteractable)#0.2.0 부터since 0.2.0소스source

터치 인터랙션 활성화 설정.

Sets whether touch interaction is enabled.

isInteractableboolean
참이면 TouchRaycaster 가 이 노드를 맞힌다.If true, TouchRaycaster can hit this node.

짝Counterpart: vanilla-engine WorldNode.set_interactable

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

터치 인터랙션 활성화 여부 반환.

Returns whether touch interaction is enabled.

반환Returnsboolean 누를 수 있으면 참.True if interactable.

짝Counterpart: vanilla-engine WorldNode.is_interactable

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

터치 누름. (TouchRaycaster에 의해 호출, 컴포넌트에 전달)

Touch press. (called by TouchRaycaster, forwarded to components)

viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.
메서드methodtouchMove(viewInputPosition)#0.2.0 부터since 0.2.0소스source

터치 이동. (TouchRaycaster에 의해 호출, 컴포넌트에 전달)

Touch move. (called by TouchRaycaster, forwarded to components)

viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.
메서드methodtouchRelease(viewInputPosition)#0.2.0 부터since 0.2.0소스source

터치 뗌. (TouchRaycaster에 의해 호출, 컴포넌트에 전달)

Touch release. (called by TouchRaycaster, forwarded to components)

viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.
메서드methodtouchCancel(viewInputPosition)#0.2.0 부터since 0.2.0소스source

터치 취소. (TouchRaycaster에 의해 호출, 컴포넌트에 전달)

Touch cancel. (called by TouchRaycaster, forwarded to components)

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