Skip to content
On this page

Class: NinePanel

九宫格绘制
将原图拆分9部分

ts
// 创建一个图片节点
const node = new Transform(Sprite);
// 获取图片组件
const sprite = node.getComponent(Sprite);
// 加载图片资源
Resource.load('1.png').then((res: IRes) => {
     // 设置纹理素材
     sprite.texture = new ImageTexture(res.data);
     // 根据纹理重新设置挂载节点的尺寸
     sprite.resize();

     const ninePanel = node.addComponent(NinePanel);
     ninePanel.left = 7;
     ninePanel.right = 7;
     ninePanel.top = 7;
     ninePanel.bottom = 7;
     node.width = 400;
     node.height = 200;
});

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new NinePanel()

组件不能单独实例化,必须通过Transform.addComponent创建

ts
const node = new Transform();
const componet = node.addComponent(Component);

Inherited from

Component.constructor

Defined in

src/core/component/Component.ts:37

Properties

emitter

emitter: EventEmitter<string | symbol, any>

事件处理器

Inherited from

Component.emitter

Defined in

src/core/component/Component.ts:27


id

id: number

用于表示组件的唯一标识

Inherited from

Component.id

Defined in

src/core/component/Component.ts:12


name

name: string = ''

组件名

Inherited from

Component.name

Defined in

src/core/component/Component.ts:17


node

node: Transform<Container>

组件挂载节点

Inherited from

Component.node

Defined in

src/core/component/Component.ts:22


redraw

redraw: boolean = false

Defined in

src/core/component/NinePanel.ts:84


texture

Optional texture: Texture<TextureResource>

Defined in

src/core/component/NinePanel.ts:68

Accessors

bottom

get bottom(): number

Returns

number

Defined in

src/core/component/NinePanel.ts:60

set bottom(val): void

Parameters

NameType
valnumber

Returns

void

Defined in

src/core/component/NinePanel.ts:63


left

get left(): number

Returns

number

Defined in

src/core/component/NinePanel.ts:33

set left(val): void

Parameters

NameType
valnumber

Returns

void

Defined in

src/core/component/NinePanel.ts:36


get right(): number

Returns

number

Defined in

src/core/component/NinePanel.ts:51

set right(val): void

Parameters

NameType
valnumber

Returns

void

Defined in

src/core/component/NinePanel.ts:54


top

get top(): number

Returns

number

Defined in

src/core/component/NinePanel.ts:42

set top(val): void

Parameters

NameType
valnumber

Returns

void

Defined in

src/core/component/NinePanel.ts:45

Methods

destroy

destroy(): void

消毁

Returns

void

Inherited from

Component.destroy

Defined in

src/core/component/Component.ts:55


onDestroy

Optional onDestroy(): void

组件被销毁时触发

Returns

void

Inherited from

Component.onDestroy

Defined in

src/core/component/Component.ts:62


start

start(): void

组件被挂载到节点时触发

Returns

void

Overrides

Component.start

Defined in

src/core/component/NinePanel.ts:70


toRedraw

toRedraw(): void

重新生成

Returns

void

Defined in

src/core/component/NinePanel.ts:81


update

Optional update(time): void

每帧调用

Parameters

NameTypeDescription
timenumber和上一帧的间隔时间 ms

Returns

void

Inherited from

Component.update

Defined in

src/core/component/Component.ts:50