Appearance
Class: Sprite
图片显示组件
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();
});
Hierarchy
↳
Sprite
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new Sprite()
组件不能单独实例化,必须通过Transform.addComponent创建
ts
const node = new Transform();
const componet = node.addComponent(Component);
Inherited from
Defined in
src/core/component/Component.ts:37
Properties
emitter
• emitter: EventEmitter
<string
| symbol
, any
>
事件处理器
Inherited from
Defined in
src/core/component/Component.ts:27
id
• id: number
用于表示组件的唯一标识
Inherited from
Defined in
src/core/component/Component.ts:12
name
• name: string
= ''
组件名
Inherited from
Defined in
src/core/component/Component.ts:17
node
组件挂载节点
Inherited from
Defined in
src/core/component/Component.ts:22
texture
• Optional
texture: Texture
<TextureResource
>
图片纹理,储存图片的相关信息
Defined in
src/core/component/Sprite.ts:23
Methods
destroy
▸ destroy(): void
消毁
Returns
void
Inherited from
Defined in
src/core/component/Component.ts:55
onDestroy
▸ Optional
onDestroy(): void
组件被销毁时触发
Returns
void
Inherited from
Defined in
src/core/component/Component.ts:62
resize
▸ resize(): void
根据当前图片纹理,重置节点尺寸信息
ts
const node = new Transform(Sprite);
const sprite = node.getComponent(Sprite)!;
sprite.resize();
Returns
void
Defined in
src/core/component/Sprite.ts:37
start
▸ Optional
start(): void
组件被挂载到节点时触发
Returns
void
Inherited from
Defined in
src/core/component/Component.ts:44
update
▸ Optional
update(time
): void
每帧调用
Parameters
Name | Type | Description |
---|---|---|
time | number | 和上一帧的间隔时间 ms |
Returns
void