Appearance
Class: SpriteSheetAnimation
适用于texturepacker的动画
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);
const ssa = node.addComponent(SpriteSheetAnimation);
// 设置每秒播放帧数
ssa.fps = 8;
// 设置为无限循环播放
ssa.loop = -1;
const func = () => {
console.log('播放到第', ssa.time, '帧');
};
ssa.addFrameAction(2, func, this);
ssa.emitter.on(Animation.Event.ENDED, () => {
console.log('单次动画播放完成');
ssa.removeFrameAction(2, func, this);
}, this);
spriteSheet.load(json.data, img);
// 需要在下一帧才能正常播放
ticker.once('update', () => {
ssa.play('Attack');
}, this);
Hierarchy
↳
SpriteSheetAnimation
Table of contents
Constructors
Properties
- animation
- animations
- emitter
- fps
- id
- loop
- name
- node
- paused
- playCount
- speed
- spriteSheet
- time
- timeMax
- timeline
- total
- Event
Accessors
Methods
- addFrameAction
- addTimeline
- destroy
- next
- nextAction
- onDestroy
- play
- prev
- puase
- removeFrameAction
- setTimeline
- start
- stop
- update
Constructors
constructor
• new SpriteSheetAnimation()
组件不能单独实例化,必须通过Transform.addComponent创建
ts
const node = new Transform();
const componet = node.addComponent(Component);
Inherited from
Defined in
src/core/component/Component.ts:37
Properties
animation
• animation: string
= 'default'
Inherited from
Defined in
src/core/component/Animation.ts:107
animations
• animations: Record
<string
, Timeline
<{}>[]> = {}
动画配置
Inherited from
Defined in
src/core/component/Animation.ts:46
emitter
• emitter: EventEmitter
<string
| symbol
, any
>
事件处理器
Inherited from
Defined in
src/core/component/Component.ts:27
fps
• fps: number
= 60
播放的帧速率,按照每秒计算,每秒播放的帧数
Defined in
src/core/component/SpriteSheetAnimation.ts:43
id
• id: number
用于表示组件的唯一标识
Inherited from
Defined in
src/core/component/Component.ts:12
loop
• loop: number
= 0
循环次数,0:不循环,-1:一直循环
Inherited from
Defined in
src/core/component/Animation.ts:112
name
• name: string
= ''
组件名
Inherited from
Defined in
src/core/component/Component.ts:17
node
组件挂载节点
Inherited from
Defined in
src/core/component/Component.ts:22
paused
• paused: boolean
= true
指示是否被暂停
Inherited from
Defined in
src/core/component/Animation.ts:125
playCount
• playCount: number
= 0
已经播放次数
Inherited from
Defined in
src/core/component/Animation.ts:116
speed
• speed: number
= 1
播放速度100%
Inherited from
Defined in
src/core/component/Animation.ts:120
spriteSheet
• spriteSheet: SpriteSheet
Defined in
src/core/component/SpriteSheetAnimation.ts:45
time
• time: number
= 0
当前时间线
Inherited from
Defined in
src/core/component/Animation.ts:32
timeMax
• timeMax: number
= 0
动画总长
Inherited from
Defined in
src/core/component/Animation.ts:24
timeline
• timeline: EventEmitter
<string
| symbol
, any
>
用于记录回调的时间线,在target时间线后执行
Inherited from
Defined in
src/core/component/Animation.ts:19
total
• total: number
= 0
最大帧数
Inherited from
Defined in
src/core/component/Animation.ts:28
Event
▪ Static
Event: Object
Type declaration
Name | Type | Description |
---|---|---|
ENDED | "ended" | 动画播放完成 |
Inherited from
Defined in
src/core/component/Animation.ts:10
Accessors
targets
• get
targets(): Timeline
<{}>[]
时间线
每一个对象一个时间线
还有一个总时间线,可以用于记录一些信息
Returns
Timeline
<{}>[]
Inherited from
Animation.targets
Defined in
src/core/component/Animation.ts:39
Methods
addFrameAction
▸ addFrameAction(time
, callback
, target
): void
添加事件
Parameters
Name | Type |
---|---|
time | number |
callback | () => void |
target | any |
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:198
addTimeline
▸ addTimeline(timeline
): void
添加一个熟悉变更时间线
Parameters
Name | Type |
---|---|
timeline | Timeline <{}> |
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:84
destroy
▸ destroy(): void
消毁
Returns
void
Inherited from
Defined in
src/core/component/Component.ts:55
next
▸ next(): void
播放下一帧
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:53
nextAction
▸ Protected
nextAction(val
): void
每次当需要更新帧动画时调用
Parameters
Name | Type | Description |
---|---|---|
val | Timeline <{}> | 即将更新的帧动画配置 |
Returns
void
Overrides
Defined in
src/core/component/SpriteSheetAnimation.ts:70
onDestroy
▸ Optional
onDestroy(): void
组件被销毁时触发
Returns
void
Inherited from
Defined in
src/core/component/Component.ts:62
play
▸ play(): void
播放
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:127
▸ play(name
): void
播放
Parameters
Name | Type | Description |
---|---|---|
name | string | 要播放的动画 |
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:128
▸ play(loop
): void
播放
Parameters
Name | Type | Description |
---|---|---|
loop | number | 要循环的次数 |
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:129
▸ play(name
, loop
): void
播放
Parameters
Name | Type | Description |
---|---|---|
name | string | 要播放的动画 |
loop | number | 要循环的次数 |
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:130
prev
▸ prev(): void
播放上一帧
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:103
puase
▸ puase(): void
暂停
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:168
removeFrameAction
▸ removeFrameAction(time
, callback
, target
): void
移除事件
Parameters
Name | Type |
---|---|
time | number |
callback | () => void |
target | any |
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:205
setTimeline
▸ setTimeline(timelines
, name?
): void
设置一个属性变更时间线
Parameters
Name | Type |
---|---|
timelines | Timeline <{}>[] |
name? | string |
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:93
start
▸ start(): void
组件被挂载到节点时触发
Returns
void
Overrides
Defined in
src/core/component/SpriteSheetAnimation.ts:47
stop
▸ stop(): void
停止
Returns
void
Inherited from
Defined in
src/core/component/Animation.ts:160
update
▸ update(time
): void
每帧调用
Parameters
Name | Type | Description |
---|---|---|
time | number | 和上一帧的间隔时间 ms |
Returns
void