Appearance
Class: SpriteSheet
图集处理,可用于逐帧动画
配合Sprite可显示图片
配合动画组件可以处理动画
ts
let json = await Resource.load('./example/assets/animations/Samurai/Attack.json');
let img = await Resource.load('./example/assets/animations/Samurai/Attack.png');
// 如果要控制动画大小可以使用父节点包裹的方式控制scale属性
const group = app.stage.addChild(new Transform);
group.scale.set(2);
const node = group.addChild(new Transform(Sprite));
const sprite = node.getComponent(Sprite)!;
const spriteSheet = node.addComponent(SpriteSheet);
spriteSheet.load(json.data, img);
// 需要在下一帧才能正常切换
ticker.once('update', () => {
spriteSheet.show('0.png');
sprite.resize();
}, this);
Hierarchy
↳
SpriteSheet
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new SpriteSheet()
组件不能单独实例化,必须通过Transform.addComponent创建
ts
const node = new Transform();
const componet = node.addComponent(Component);
Inherited from
Defined in
src/core/component/Component.ts:37
Properties
animations
• animations: Record
<string
, string
[]> = {}
动画配置
Defined in
src/core/component/SpriteSheet.ts:90
emitter
• emitter: EventEmitter
<string
| symbol
, any
>
事件处理器
Inherited from
Defined in
src/core/component/Component.ts:27
frames
• frames: Record
<string
, Texture
<TextureResource
>> = {}
纹理集
Defined in
src/core/component/SpriteSheet.ts:86
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
sprite
• sprite: Sprite
展示的节点
Defined in
src/core/component/SpriteSheet.ts:94
Methods
add
▸ add(res
, data
, name
): void
添加一个素材
Parameters
Name | Type | Description |
---|---|---|
res | TextureResource | 资源 |
data | AtlasFrame | 配置 |
name | string | 内部别名 |
Returns
void
Defined in
src/core/component/SpriteSheet.ts:122
destroy
▸ destroy(): void
消毁
Returns
void
Inherited from
Defined in
src/core/component/Component.ts:55
get
▸ get(name
): Texture
<TextureResource
>
获取素材
Parameters
Name | Type |
---|---|
name | string |
Returns
Defined in
src/core/component/SpriteSheet.ts:104
load
▸ load(config
, res?
): void
加载图集
如果没有传入资源,则使用配置里面的资源路径进行加载,但是还是要提前保证路径资源已经被提前加载
Parameters
Name | Type | Description |
---|---|---|
config | SheetFrames | 配置 |
res? | IRes | 资源 |
Returns
void
Defined in
src/core/component/SpriteSheet.ts:152
onDestroy
▸ Optional
onDestroy(): void
组件被销毁时触发
Returns
void
Inherited from
Defined in
src/core/component/Component.ts:62
set
▸ set(name
, texture
): void
设置要显示的素材
Parameters
Name | Type |
---|---|
name | string |
texture | Texture <TextureResource > |
Returns
void
Defined in
src/core/component/SpriteSheet.ts:112
show
▸ show(name
): void
设置要现实的素材
Parameters
Name | Type | Description |
---|---|---|
name | string | 内部别名 |
Returns
void
Defined in
src/core/component/SpriteSheet.ts:142
start
▸ start(): void
组件被挂载到节点时触发
Returns
void
Overrides
Defined in
src/core/component/SpriteSheet.ts:96
update
▸ Optional
update(time
): void
每帧调用
Parameters
Name | Type | Description |
---|---|---|
time | number | 和上一帧的间隔时间 ms |
Returns
void