Skip to content
On this page

Class: Node<T>

节点,用于构建整个项目的节点树,也是所有组件挂载的节点

ts
const node = new Transform();

Type parameters

NameType
Textends Container = Container

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Node<T>(classConstructor?)

Type parameters

NameType
Textends Container<T> = Container

Parameters

NameType
classConstructor?Constructor<T>

Overrides

Transform.constructor

Defined in

src/core/transform/Node.ts:9

Properties

_anchor

_anchor: Vector2

Inherited from

Transform._anchor

Defined in

src/core/transform/Transform.ts:175


_rotation

_rotation: number = 0

Inherited from

Transform._rotation

Defined in

src/core/transform/Transform.ts:164


active

active: boolean = true

Inherited from

Transform.active

Defined in

src/core/transform/Transform.ts:27


alone

alone: boolean = false

Inherited from

Transform.alone

Defined in

src/core/transform/Transform.ts:24


alpha

alpha: number = 1

透明度

Inherited from

Transform.alpha

Defined in

src/core/transform/Transform.ts:237


children

children: Transform<Container>[] = []

子节点

Inherited from

Transform.children

Defined in

src/core/transform/Transform.ts:313


components

components: Component[] = []

所有组件
默认包含一个容器组件,当添加了其他容器组件后自动替换,只能包含一个视觉组件

Inherited from

Transform.components

Defined in

src/core/transform/Transform.ts:206


container

container: T

Inherited from

Transform.container

Defined in

src/core/transform/Transform.ts:201


deliver

deliver: boolean = true

是否继续向父元素传递事件(冒泡)

Inherited from

Transform.deliver

Defined in

src/core/transform/Transform.ts:228


display

Optional display: T

Defined in

src/core/transform/Node.ts:7


emitter

emitter: EventEmitter<TransformEvent, any>

Inherited from

Transform.emitter

Defined in

src/core/transform/Transform.ts:30


id

id: number = 0

Inherited from

Transform.id

Defined in

src/core/transform/Transform.ts:22


name

name: string = 'node'

Inherited from

Transform.name

Defined in

src/core/transform/Transform.ts:29


parent

Optional parent: Transform<Container>

父节点

Inherited from

Transform.parent

Defined in

src/core/transform/Transform.ts:211


pierce

pierce: boolean = false

是否穿透,可触发非父元素外的其它元素事件

Inherited from

Transform.pierce

Defined in

src/core/transform/Transform.ts:232


redraw

redraw: boolean = false

Inherited from

Transform.redraw

Defined in

src/core/transform/Transform.ts:32


Event

Static Event: Object

事件

Type declaration

NameTypeDescription
ADDED"ADDED"当添加到显示舞台时
CHANGE_DISPLY"CHANGE_DISPLY"可见元素发生变化时(需要渲染的元素)
CHILD_ADDED"CHILD_ADDED"当添加新的字节点时
REMOVED"REMOVED"当被移除于舞台时
REPOSITION"REPOSITION"位置发生变化
RESIZE"RESIZE"尺寸发生变化时
TICKER_AFTER"TICKER_AFTER"帧刷新后
TICKER_BEFORE"TICKER_BEFORE"帧刷新前

Inherited from

Transform.Event

Defined in

src/core/transform/Transform.ts:36

Accessors

anchor

get anchor(): Vector2

锚点

Returns

Vector2

Inherited from

Transform.anchor

Defined in

src/core/transform/Transform.ts:179

set anchor(value): void

Parameters

NameType
valueVector2

Returns

void

Inherited from

Transform.anchor

Defined in

src/core/transform/Transform.ts:182


anchorX

get anchorX(): number

Returns

number

Inherited from

Transform.anchorX

Defined in

src/core/transform/Transform.ts:186

set anchorX(val): void

Parameters

NameType
valnumber

Returns

void

Inherited from

Transform.anchorX

Defined in

src/core/transform/Transform.ts:189


anchorY

get anchorY(): number

Returns

number

Inherited from

Transform.anchorY

Defined in

src/core/transform/Transform.ts:193

set anchorY(val): void

Parameters

NameType
valnumber

Returns

void

Inherited from

Transform.anchorY

Defined in

src/core/transform/Transform.ts:196


height

get height(): number

Returns

number

Inherited from

Transform.height

Defined in

src/core/transform/Transform.ts:130

set height(val): void

Parameters

NameType
valnumber

Returns

void

Inherited from

Transform.height

Defined in

src/core/transform/Transform.ts:133


position

get position(): Vector2

位置

Returns

Vector2

Inherited from

Transform.position

Defined in

src/core/transform/Transform.ts:90

set position(value): void

Parameters

NameType
valueVector2

Returns

void

Inherited from

Transform.position

Defined in

src/core/transform/Transform.ts:93


rotation

get rotation(): number

旋转

Returns

number

Inherited from

Transform.rotation

Defined in

src/core/transform/Transform.ts:168

set rotation(value): void

Parameters

NameType
valuenumber

Returns

void

Inherited from

Transform.rotation

Defined in

src/core/transform/Transform.ts:171


scale

get scale(): Vector2

缩放

Returns

Vector2

Inherited from

Transform.scale

Defined in

src/core/transform/Transform.ts:143

set scale(value): void

Parameters

NameType
valueVector2

Returns

void

Inherited from

Transform.scale

Defined in

src/core/transform/Transform.ts:146


scaleX

get scaleX(): number

Returns

number

Inherited from

Transform.scaleX

Defined in

src/core/transform/Transform.ts:150

set scaleX(val): void

Parameters

NameType
valnumber

Returns

void

Inherited from

Transform.scaleX

Defined in

src/core/transform/Transform.ts:153


scaleY

get scaleY(): number

Returns

number

Inherited from

Transform.scaleY

Defined in

src/core/transform/Transform.ts:157

set scaleY(val): void

Parameters

NameType
valnumber

Returns

void

Inherited from

Transform.scaleY

Defined in

src/core/transform/Transform.ts:160


size

get size(): Vector2

大小

Returns

Vector2

Inherited from

Transform.size

Defined in

src/core/transform/Transform.ts:116

set size(value): void

Parameters

NameType
valueVector2

Returns

void

Inherited from

Transform.size

Defined in

src/core/transform/Transform.ts:119


touch

get touch(): boolean

Returns

boolean

Inherited from

Transform.touch

Defined in

src/core/transform/Transform.ts:221

set touch(val): void

触摸事件,默认关闭

Parameters

NameType
valboolean

Returns

void

Inherited from

Transform.touch

Defined in

src/core/transform/Transform.ts:217


width

get width(): number

Returns

number

Inherited from

Transform.width

Defined in

src/core/transform/Transform.ts:124

set width(val): void

Parameters

NameType
valnumber

Returns

void

Inherited from

Transform.width

Defined in

src/core/transform/Transform.ts:127


x

get x(): number

Returns

number

Inherited from

Transform.x

Defined in

src/core/transform/Transform.ts:97

set x(val): void

Parameters

NameType
valnumber

Returns

void

Inherited from

Transform.x

Defined in

src/core/transform/Transform.ts:100


y

get y(): number

Returns

number

Inherited from

Transform.y

Defined in

src/core/transform/Transform.ts:105

set y(val): void

Parameters

NameType
valnumber

Returns

void

Inherited from

Transform.y

Defined in

src/core/transform/Transform.ts:108

Methods

addChild

addChild<U>(transform, props?): U

插入一个子节点

Type parameters

NameType
Uextends Transform<Container, U>

Parameters

NameTypeDescription
transformU待插入的节点
props?Props<U>-

Returns

U

Inherited from

Transform.addChild

Defined in

src/core/transform/Transform.ts:319


addChildAt

addChildAt(child, index): void

在指定位置插入节点

Parameters

NameTypeDescription
childTransform<Container>待插入的节点
indexnumber要插入的位置

Returns

void

Inherited from

Transform.addChildAt

Defined in

src/core/transform/Transform.ts:334


addComponent

addComponent<T>(classConstructor, props?): T

添加一个组件

Type parameters

NameType
Textends Component<T>

Parameters

NameTypeDescription
classConstructorT | Constructor<T>要挂载的组件
props?Props<T>-

Returns

T

Inherited from

Transform.addComponent

Defined in

src/core/transform/Transform.ts:243


destroy

destroy(): void

消毁

Returns

void

Inherited from

Transform.destroy

Defined in

src/core/transform/Transform.ts:383


find

find(path): Transform<Container>

路径查找节点

ts
// 创建身体节点
const body = new Transform();
// 设置名称
body.name = 'body';
// 创建头部节点
const head = new Transform();
// 设置名称
head.name = 'head';
// 创建左眼节点
const leftEye = new Transform();
// 设置名称
leftEye.name = 'lEye';
// 创建右眼节点
const rightEye = new Transform();
// 设置名称
rightEye.name = 'rEye';
// 将右眼添加到头部
head.addChild(leftEye);
// 将左眼添加到头部
head.addChild(rightEye);
// 将头部添加到身体
body.addChild(head);
// 从身体获取左眼
body.find('head/lEye');
// 从身体获取右眼
body.find('head/rEye');

Path

  • 路径

Parameters

NameType
pathstring | string[]

Returns

Transform<Container>

Inherited from

Transform.find

Defined in

src/core/transform/Transform.ts:422


getComponent

getComponent<T>(classConstructor): T

获取单个组件,获取首个匹配到的组件

Type parameters

NameType
Textends Component<T>

Parameters

NameTypeDescription
classConstructorConstructor<T>组件

Returns

T

Inherited from

Transform.getComponent

Defined in

src/core/transform/Transform.ts:268


getComponents

getComponents<T>(classConstructor): T[]

获取所有组件

Type parameters

Name
T

Parameters

NameTypeDescription
classConstructorConstructor<T>组件

Returns

T[]

  • 所有满足条件的组件

Inherited from

Transform.getComponents

Defined in

src/core/transform/Transform.ts:276


getComponentsInChildren

getComponentsInChildren<T>(classConstructor): T[]

从子节点获取所有组件,不会包含当前节点
递归查询所有子节点的

Type parameters

Name
T

Parameters

NameTypeDescription
classConstructorConstructor<T>组件

Returns

T[]

  • 所有满足条件的组件

Inherited from

Transform.getComponentsInChildren

Defined in

src/core/transform/Transform.ts:292


getOffset

getOffset(): Vector2

获取右上角偏真实移量

Returns

Vector2

Inherited from

Transform.getOffset

Defined in

src/core/transform/Transform.ts:460


getWordPoisition

getWordPoisition(): Vector2

获取相对世界坐标

Returns

Vector2

Inherited from

Transform.getWordPoisition

Defined in

src/core/transform/Transform.ts:467


getWordScale

getWordScale(): Vector2

获取相对于世界的缩放

Returns

Vector2

Inherited from

Transform.getWordScale

Defined in

src/core/transform/Transform.ts:479


onDestroy

Optional onDestroy(): void

Returns

void

Inherited from

Transform.onDestroy

Defined in

src/core/transform/Transform.ts:389


removeAllComponent

removeAllComponent(): void

移除所有组件

Returns

void

Inherited from

Transform.removeAllComponent

Defined in

src/core/transform/Transform.ts:258


removeChild

removeChild(transform): void

移除一个节点

Parameters

NameTypeDescription
transformTransform<Container>将要移除的节点

Returns

void

Inherited from

Transform.removeChild

Defined in

src/core/transform/Transform.ts:346


removeChildAt

removeChildAt(index): Transform<Container>

移除一个指定位置的元素

Parameters

NameTypeDescription
indexnumber要移除节点的位置

Returns

Transform<Container>

Inherited from

Transform.removeChildAt

Defined in

src/core/transform/Transform.ts:359


removeChildren

removeChildren(): void

移除所有子元素

Returns

void

Inherited from

Transform.removeChildren

Defined in

src/core/transform/Transform.ts:368


removeComponent

removeComponent(component): void

移除一个组件

Parameters

NameTypeDescription
componentComponent将要移除的组件

Returns

void

Inherited from

Transform.removeComponent

Defined in

src/core/transform/Transform.ts:251


select

select(queryString): any[]

根据name查找节点

Parameters

NameType
queryStringstring | string[]

Returns

any[]

Inherited from

Transform.select

Defined in

src/core/transform/Transform.ts:441


start

Optional start(): any

Returns

any

Defined in

src/core/transform/Node.ts:15


update

update(time): void

Parameters

NameType
timenumber

Returns

void

Inherited from

Transform.update

Defined in

src/core/transform/Transform.ts:376