misc/nodelayout
노드 레이아웃.
Node layout.
NodeLayoutextends Object
노드 레이아웃.
- 지역 변수 없이 노드 계층 구조를 선언적으로 구성하는 플루언트 빌더.
- Unreal Slate / Flutter 위젯과 유사한 구조.
- Vector2 없이 숫자쌍(x, y)으로 모든 위치/크기를 지정한다.
- create(nodeClass)로 노드 타입을 지정한다. (기본값: WorldNode)
사용 예:
const panel = NodeLayout.create(WorldNode)
.pivot(Pivot.middleCenter)
.contentSize(680, 900)
.component(Paint, (c) => { c.setColor(new Color(0.1, 0.1, 0.1, 1)); })
.children(
NodeLayout.create(WorldNode)
.contentSize(120, 70)
.component(Text, (c) => { c.setText("확인"); })
)
.build();Node layout.
- A fluent builder that declaratively composes the node hierarchy without local variables.
- A structure similar to Unreal Slate / Flutter widgets.
- Specifies all positions/sizes with number pairs (x, y) without Vector2.
- Specifies the node type with create(nodeClass). (default: WorldNode)
Example:
const panel = NodeLayout.create(WorldNode)
.pivot(Pivot.middleCenter)
.contentSize(680, 900)
.component(Paint, (c) => { c.setColor(new Color(0.1, 0.1, 0.1, 1)); })
.children(
NodeLayout.create(WorldNode)
.contentSize(120, 70)
.component(Text, (c) => { c.setText("OK"); })
)
.build();import { Engine, EngineConfiguration, Scene, NodeLayout, WorldNode, Paint, Pivot, Color } from "./build/vanilla.js";
class MainScene extends Scene {
initialize(engine) {
super.initialize(engine);
const root = this.getRoot();
const panelLayout = NodeLayout.create(WorldNode)
.name("panel")
.pivot(Pivot.middleCenter)
.localPosition(320, 180)
.contentSize(300, 160)
.component(Paint, (paint) => {
paint.setColor(new Color(0.1, 0.1, 0.1, 1));
})
.children(
NodeLayout.create(WorldNode)
.name("button")
.pivot(Pivot.middleCenter)
.localPosition(150, 110)
.contentSize(120, 40)
.component(Paint, (paint) => {
paint.setColor(new Color(0.2, 0.6, 1, 1));
})
);
const panelNode = panelLayout.build(root);
console.log(panelNode.getName(), panelNode.getChildCount());
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());생성.
Constructor.
- nodeClassFunction
- 만들 노드의 클래스. (없으면 WorldNode)Class of the node to create. (WorldNode if omitted)
짝Counterpart: vanilla-engine NodeLayout.new
부채꼴 배치. (정적, 손패 카드처럼 노드들을 호 위에 펼친다)
- 가운데 항목이 baseAngleRadian 방향(기본 위쪽)을 보도록 좌우 대칭으로 벌린다.
- rotateNodes 가 참이면 각 노드의 회전도 호의 접선에 맞춘다. (노드의 회전은 도 단위라 라디안을 도로 바꿔 건다)
Fan layout. (static, spreads nodes over an arc like cards in a hand)
- Spreads them symmetrically left and right so the middle item faces the baseAngleRadian direction (default up).
- If rotateNodes is true, also aligns each node's rotation to the arc's tangent. (Node rotation is in degrees, so radians are converted to degrees)
- nodeListWorldNode[]
- 펼칠 노드 목록.List of nodes to fan out.
- optionsobject
- { centerX, centerY, radius, angleStepRadian = 0.12, baseAngleRadian = -PI/2, rotateNodes = true }
짝Counterpart: vanilla-engine NodeLayout.arrange_fan
import { NodeLayout, WorldNode } from "./build/vanilla.js";
const cardList = [];
for (let index = 0; index < 5; ++index) {
cardList.push(new WorldNode());
}
NodeLayout.arrangeFan(cardList, { centerX: 320, centerY: 600, radius: 400, angleStepRadian: 0.12 });
for (const card of cardList) {
const position = card.getLocalPosition();
const rotation = card.getLocalRotation();
console.log(position.x.toFixed(1), position.y.toFixed(1), rotation.toFixed(1));
}레이아웃 인스턴스 생성.
Creates a layout instance.
- nodeClassFunction
- 만들 노드의 클래스. (없으면 WorldNode)Class of the node to create. (WorldNode if omitted)
반환ReturnsNodeLayout 새 레이아웃.New layout.
짝Counterpart: vanilla-engine NodeLayout.create
노드 직접 접근. (빌더에 없는 속성을 설정할 때 사용)
Direct node access. (Used to set properties not in the builder)
- callbackFunction
- 노드를 받아 직접 고칠 함수. (node) => voidFunction that receives the node and modifies it directly. (node) => void
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.apply
활성화 설정.
Sets active.
- activeboolean
- 참이면 노드를 켠다.If true, activates the node.
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.active
이름 설정.
Sets the name.
- namestring
- 노드 이름.Node name.
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.name
컴포넌트 추가 및 설정.
- callback이 없으면 컴포넌트만 추가한다.
Adds and configures a component.
- If there is no callback, only adds the component.
- componentTypeFunction
- 더할 컴포넌트 클래스.Component class to add.
- callbackFunction
- 더한 컴포넌트를 받아 설정할 함수. (component) => void, 없으면 더하기만 한다Function that receives the added component to set it up. (component) => void, only adds if omitted
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.component
자식 레이아웃 추가.
- 가변 인자로 여러 자식 레이아웃을 한번에 추가할 수 있다.
Adds child layouts.
- Several child layouts can be added at once as variadic arguments.
- ...layouts...NodeLayout
- 자식으로 붙일 레이아웃들. (build 때 함께 빌드한다)Layouts to attach as children. (built together on build)
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.children
로컬 위치 설정.
Sets the local position.
- xnumber
- 지역 X 좌표.Local X coordinate.
- ynumber
- 지역 Y 좌표. (앞서 부른 anchoredPosition 은 버린다, 나중에 부른 것이 이긴다)Local Y coordinate. (An anchoredPosition called earlier is dropped, the later call wins)
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.local_position
피벗 설정.
Sets the pivot.
- pivotVector2
- 피벗. (0 ~ 1, Pivot 상수)Pivot. (0 ~ 1, Pivot constants)
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.pivot
콘텐츠 크기 설정.
Sets the content size.
- xnumber
- 콘텐츠 너비. (픽셀)Content width. (pixels)
- ynumber
- 콘텐츠 높이. (픽셀)Content height. (pixels)
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.content_size
로컬 스케일 설정.
Sets the local scale.
- xnumber
- 가로 배율.Horizontal scale.
- ynumber
- 세로 배율.Vertical scale.
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.local_scale
부모 노드 설정. (build()에 인자 없이 호출 시 이 부모에 자식으로 추가된다.)
Sets the parent node. (When build() is called without arguments, it is added as a child of this parent.)
- parentNode*
- build 가 노드를 붙일 부모 노드.Parent node that build attaches the node to.
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.parent
단일 앵커 설정. (WorldNode.setAnchor)
Sets a single anchor. (WorldNode.setAnchor)
- xnumber
- 앵커 X. (부모 크기 기준 비율, 0 ~ 1 로 자른다)Anchor X. (Ratio of the parent size, clamped to 0 ~ 1)
- ynumber
- 앵커 Y. (부모 크기 기준 비율, 0 ~ 1 로 자른다)Anchor Y. (Ratio of the parent size, clamped to 0 ~ 1)
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.anchor
앵커 기준 위치 오프셋 설정.
- build 때 노드를 부모에 붙인 뒤 부모 contentSize 의 앵커 점 기준으로 건다. (빌드 중에는 노드에 아직 부모가 없다)
- 앵커는 이 메서드를 부를 때의 앵커를 쓴다. (앵커는 먼저 정한다, 나중에 부른 localPosition 이 이긴다)
Sets the position offset relative to the anchor.
- Applied in build after the node is attached to its parent, relative to the anchor point of the parent contentSize. (While building, the node has no parent yet)
- Uses the anchor at the time this method is called. (Set the anchor first, a later localPosition call wins)
- xnumber
- 앵커 기준 X. (픽셀, build 에서 붙일 부모가 없으면 지역 X 로 들어간다)X relative to the anchor. (Pixels, used as the local X when build has no parent to attach to)
- ynumber
- 앵커 기준 Y. (픽셀, build 에서 붙일 부모가 없으면 지역 Y 로 들어간다)Y relative to the anchor. (Pixels, used as the local Y when build has no parent to attach to)
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.anchored_position
import { NodeLayout, WorldNode } from "./build/vanilla.js";
const panelNode = NodeLayout.create(WorldNode)
.contentSize(680, 900)
.children(
NodeLayout.create(WorldNode)
.name("corner")
.anchor(1, 1)
.anchoredPosition(-10, -20)
)
.build();
const cornerNode = panelNode.findChildByName("corner");
const localPosition = cornerNode.getLocalPosition();
console.log(localPosition.x, localPosition.y);마스크 활성화 설정.
Sets whether the mask is enabled.
- enabledboolean
- 참이면 Mask 컴포넌트를 붙이고 거짓이면 뗀다.If true, adds a Mask component; if false, removes it.
반환ReturnsNodeLayout 이 레이아웃. (이어 부르기용)This layout. (for chaining)
짝Counterpart: vanilla-engine NodeLayout.mask_enabled
빌드.
- 자식 레이아웃을 모두 재귀적으로 빌드한다.
- parent 인자가 제공되면 그 부모에 자식으로 추가한다.
- parent 인자가 없고 parent() 메서드로 지정된 부모가 있으면 그 부모에 자식으로 추가한다.
- 완성된 노드를 반환한다.
Build.
- Recursively builds all child layouts.
- If the parent argument is given, adds it as a child of that parent.
- If there is no parent argument and a parent was set by the parent() method, adds it as a child of that parent.
- Returns the finished node.
- parent*
- 만든 노드를 붙일 부모. (없으면 parent() 로 정한 부모, 둘 다 없으면 붙이지 않는다)Parent to attach the built node to. (The parent set with parent() if omitted, not attached if neither)
반환Returns* 만든 노드.The built node.
짝Counterpart: vanilla-engine NodeLayout.build