Appearance
Class: Thing<T>
节点,用于构建整个项目的节点树,也是所有组件挂载的节点
ts
const node = new Transform();
Type parameters
Name | Type |
---|---|
T | extends Container = Container |
Hierarchy
Transform
<T
>↳
Thing
Table of contents
Constructors
Properties
- _anchor
- _rotation
- active
- alone
- alpha
- children
- components
- container
- deliver
- emitter
- id
- name
- parent
- pierce
- redraw
- Event
Accessors
Methods
- addChild
- addChildAt
- addComponent
- destroy
- find
- getComponent
- getComponents
- getComponentsInChildren
- getOffset
- getWordPoisition
- getWordScale
- onDestroy
- removeAllComponent
- removeChild
- removeChildAt
- removeChildren
- removeComponent
- render
- select
- start
- update
Constructors
constructor
• new Thing<T
>(classConstructor?
)
Type parameters
Name | Type |
---|---|
T | extends Container <T > = Container |
Parameters
Name | Type |
---|---|
classConstructor? | Constructor <T > |
Overrides
Defined in
Properties
_anchor
• _anchor: Vector2
Inherited from
Defined in
src/core/transform/Transform.ts:175
_rotation
• _rotation: number
= 0
Inherited from
Defined in
src/core/transform/Transform.ts:164
active
• active: boolean
= true
Inherited from
Defined in
src/core/transform/Transform.ts:27
alone
• alone: boolean
= false
Inherited from
Defined in
src/core/transform/Transform.ts:24
alpha
• alpha: number
= 1
透明度
Inherited from
Defined in
src/core/transform/Transform.ts:237
children
• children: Transform
<Container
>[] = []
子节点
Inherited from
Defined in
src/core/transform/Transform.ts:313
components
• components: Component
[] = []
所有组件
默认包含一个容器组件,当添加了其他容器组件后自动替换,只能包含一个视觉组件
Inherited from
Defined in
src/core/transform/Transform.ts:206
container
• container: T
Inherited from
Defined in
src/core/transform/Transform.ts:201
deliver
• deliver: boolean
= true
是否继续向父元素传递事件(冒泡)
Inherited from
Defined in
src/core/transform/Transform.ts:228
emitter
• emitter: EventEmitter
<TransformEvent
, any
>
Inherited from
Defined in
src/core/transform/Transform.ts:30
id
• id: number
= 0
Inherited from
Defined in
src/core/transform/Transform.ts:22
name
• name: string
= 'node'
Inherited from
Defined in
src/core/transform/Transform.ts:29
parent
• Optional
parent: Transform
<Container
>
父节点
Inherited from
Defined in
src/core/transform/Transform.ts:211
pierce
• pierce: boolean
= false
是否穿透,可触发非父元素外的其它元素事件
Inherited from
Defined in
src/core/transform/Transform.ts:232
redraw
• redraw: boolean
= false
Inherited from
Defined in
src/core/transform/Transform.ts:32
Event
▪ Static
Event: Object
事件
Type declaration
Name | Type | Description |
---|---|---|
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
Defined in
src/core/transform/Transform.ts:36
Accessors
anchor
• get
anchor(): Vector2
锚点
Returns
Inherited from
Transform.anchor
Defined in
src/core/transform/Transform.ts:179
• set
anchor(value
): void
Parameters
Name | Type |
---|---|
value | Vector2 |
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
Name | Type |
---|---|
val | number |
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
Name | Type |
---|---|
val | number |
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
Name | Type |
---|---|
val | number |
Returns
void
Inherited from
Transform.height
Defined in
src/core/transform/Transform.ts:133
position
• get
position(): Vector2
位置
Returns
Inherited from
Transform.position
Defined in
src/core/transform/Transform.ts:90
• set
position(value
): void
Parameters
Name | Type |
---|---|
value | Vector2 |
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
Name | Type |
---|---|
value | number |
Returns
void
Inherited from
Transform.rotation
Defined in
src/core/transform/Transform.ts:171
scale
• get
scale(): Vector2
缩放
Returns
Inherited from
Transform.scale
Defined in
src/core/transform/Transform.ts:143
• set
scale(value
): void
Parameters
Name | Type |
---|---|
value | Vector2 |
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
Name | Type |
---|---|
val | number |
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
Name | Type |
---|---|
val | number |
Returns
void
Inherited from
Transform.scaleY
Defined in
src/core/transform/Transform.ts:160
size
• get
size(): Vector2
大小
Returns
Inherited from
Transform.size
Defined in
src/core/transform/Transform.ts:116
• set
size(value
): void
Parameters
Name | Type |
---|---|
value | Vector2 |
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
Name | Type |
---|---|
val | boolean |
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
Name | Type |
---|---|
val | number |
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
Name | Type |
---|---|
val | number |
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
Name | Type |
---|---|
val | number |
Returns
void
Inherited from
Transform.y
Defined in
src/core/transform/Transform.ts:108
Methods
addChild
▸ addChild<U
>(transform
, props?
): U
插入一个子节点
Type parameters
Name | Type |
---|---|
U | extends Transform <Container , U > |
Parameters
Name | Type | Description |
---|---|---|
transform | U | 待插入的节点 |
props? | Props <U > | - |
Returns
U
Inherited from
Defined in
src/core/transform/Transform.ts:319
addChildAt
▸ addChildAt(child
, index
): void
在指定位置插入节点
Parameters
Name | Type | Description |
---|---|---|
child | Transform <Container > | 待插入的节点 |
index | number | 要插入的位置 |
Returns
void
Inherited from
Defined in
src/core/transform/Transform.ts:334
addComponent
▸ addComponent<T
>(classConstructor
, props?
): T
添加一个组件
Type parameters
Name | Type |
---|---|
T | extends Component <T > |
Parameters
Name | Type | Description |
---|---|---|
classConstructor | T | Constructor <T > | 要挂载的组件 |
props? | Props <T > | - |
Returns
T
Inherited from
Defined in
src/core/transform/Transform.ts:243
destroy
▸ destroy(): void
消毁
Returns
void
Inherited from
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
Name | Type |
---|---|
path | string | string [] |
Returns
Inherited from
Defined in
src/core/transform/Transform.ts:422
getComponent
▸ getComponent<T
>(classConstructor
): T
获取单个组件,获取首个匹配到的组件
Type parameters
Name | Type |
---|---|
T | extends Component <T > |
Parameters
Name | Type | Description |
---|---|---|
classConstructor | Constructor <T > | 组件 |
Returns
T
Inherited from
Defined in
src/core/transform/Transform.ts:268
getComponents
▸ getComponents<T
>(classConstructor
): T
[]
获取所有组件
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
classConstructor | Constructor <T > | 组件 |
Returns
T
[]
- 所有满足条件的组件
Inherited from
Defined in
src/core/transform/Transform.ts:276
getComponentsInChildren
▸ getComponentsInChildren<T
>(classConstructor
): T
[]
从子节点获取所有组件,不会包含当前节点
递归查询所有子节点的
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
classConstructor | Constructor <T > | 组件 |
Returns
T
[]
- 所有满足条件的组件
Inherited from
Transform.getComponentsInChildren
Defined in
src/core/transform/Transform.ts:292
getOffset
▸ getOffset(): Vector2
获取右上角偏真实移量
Returns
Inherited from
Defined in
src/core/transform/Transform.ts:460
getWordPoisition
▸ getWordPoisition(): Vector2
获取相对世界坐标
Returns
Inherited from
Defined in
src/core/transform/Transform.ts:467
getWordScale
▸ getWordScale(): Vector2
获取相对于世界的缩放
Returns
Inherited from
Defined in
src/core/transform/Transform.ts:479
onDestroy
▸ Optional
onDestroy(): void
Returns
void
Inherited from
Defined in
src/core/transform/Transform.ts:389
removeAllComponent
▸ removeAllComponent(): void
移除所有组件
Returns
void
Inherited from
Defined in
src/core/transform/Transform.ts:258
removeChild
▸ removeChild(transform
): void
移除一个节点
Parameters
Name | Type | Description |
---|---|---|
transform | Transform <Container > | 将要移除的节点 |
Returns
void
Inherited from
Defined in
src/core/transform/Transform.ts:346
removeChildAt
▸ removeChildAt(index
): Transform
<Container
>
移除一个指定位置的元素
Parameters
Name | Type | Description |
---|---|---|
index | number | 要移除节点的位置 |
Returns
Inherited from
Defined in
src/core/transform/Transform.ts:359
removeChildren
▸ removeChildren(): void
移除所有子元素
Returns
void
Inherited from
Defined in
src/core/transform/Transform.ts:368
removeComponent
▸ removeComponent(component
): void
移除一个组件
Parameters
Name | Type | Description |
---|---|---|
component | Component | 将要移除的组件 |
Returns
void
Inherited from
Defined in
src/core/transform/Transform.ts:251
render
▸ Optional
render(): Thing
<T
>
Returns
Thing
<T
>
Defined in
select
▸ select(queryString
): any
[]
根据name查找节点
Parameters
Name | Type |
---|---|
queryString | string | string [] |
Returns
any
[]
Inherited from
Defined in
src/core/transform/Transform.ts:441
start
▸ Optional
start(): void
Returns
void
Defined in
update
▸ update(time
): void
Parameters
Name | Type |
---|---|
time | number |
Returns
void