core/node/componentnode
계층적 컴포넌트 처리 객체.
Hierarchical component processing object.
ComponentNodeextends Node
계층적 컴포넌트 처리 객체.
- 컴포넌트 기능.
- 주기적 갱신 기능. (컴포넌트 포함)
Hierarchical component processing object.
- Component features.
- Periodic update features. (including components)
import { ComponentNode, Component } from "./build/vanilla.js";
class Health extends Component {
constructor() {
super();
this.hitPoint = 100;
}
}
class Poison extends Component {
require() {
return [Health];
}
tick(timeDelta) {
const node = this.getNode();
const health = node.getComponent(Health);
health.hitPoint -= 10 * timeDelta;
}
}
const node = new ComponentNode();
node.addComponent(Poison);
const health = node.getComponent(Health);
node.tick(0.5);
const hasHealth = node.hasComponent(Health);
console.log(hasHealth, health.hitPoint);생성.
Constructor.
갱신.
Update.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
짝Counterpart: vanilla-engine NodeTree.tick
하위 트리 그리기 경계가 바뀌었음을 표시. (그리는 노드 TransformNode 가 덮어쓴다, 여기서는 할 일이 없다)
- 컴포넌트를 더하거나 뺄 때, 컴포넌트를 켜고 끌 때 부른다.
Marks that the subtree draw bounds changed. (overridden by the drawing node TransformNode, nothing to do here)
- Called when a component is added or removed, and when a component is enabled or disabled.
타입으로 컴포넌트 추가.
Adds a component by type.
- componentTypeFunction
- 컴포넌트 클래스. (없으면 붙인다)Component class. (attached if missing)
반환ReturnsComponent | null 있던 컴포넌트나 새로 붙인 컴포넌트. (componentType 이 없으면 null)The existing component or a newly attached one. (null if componentType is missing)
짝Counterpart: vanilla-engine WorldNode.get_or_add_component
타입으로 컴포넌트 추가.
Adds a component by type.
- componentTypeFunction
- 붙일 컴포넌트 클래스. (인자 없이 new 로 만들고, 같은 클래스가 있어도 또 붙인다)Component class to attach. (created with new and no arguments; attached again even if the same class exists)
반환ReturnsComponent | null 새로 붙인 컴포넌트. (componentType 이 없으면 null)The newly attached component. (null if componentType is missing)
짝Counterpart: vanilla-engine NodeTree.add_component
객체로 컴포넌트 제거.
Removes a component by object.
- componentComponent
- 뗄 컴포넌트. (이 노드에 없으면 아무것도 하지 않는다)Component to detach. (does nothing if not on this node)
짝Counterpart: vanilla-engine WorldNode.remove_component
컴포넌트 보유 여부..
Whether it has the component.
- componentTypeFunction
- 찾을 컴포넌트 클래스. (자식 클래스도 맞는다)Component class to look for. (subclasses also match)
반환Returnsboolean 있으면 참.True if present.
짝Counterpart: vanilla-engine WorldNode.has_component
모든 컴포넌트 목록 반환.
Returns the list of all components.
반환ReturnsComponent[] 붙은 컴포넌트 목록. (붙인 차례, 안의 배열 그대로)List of attached components. (in attach order, the internal array as is)
짝Counterpart: vanilla-engine WorldNode.get_all_components
타입에 대한 컴포넌트 반환.
Returns the component for a type.
- componentTypeFunction
- 찾을 컴포넌트 클래스. (자식 클래스도 맞는다)Component class to look for. (subclasses also match)
반환ReturnsComponent | null 처음 맞는 컴포넌트. (없으면 null)The first matching component. (null if none)
짝Counterpart: vanilla-engine WorldNode.get_component
타입에 대한 모든 컴포넌트 반환.
Returns all components for a type.
- componentTypeFunction
- 찾을 컴포넌트 클래스. (자식 클래스도 맞는다)Component class to look for. (subclasses also match)
반환ReturnsComponent[] 맞는 컴포넌트 모두. (새 배열)All matching components. (a new array)
짝Counterpart: vanilla-engine WorldNode.get_components