Skip to content

API / Animation

类: Animation

定义于: animation/Animation.ts:38

动画播放器用来播放动画数据和管理动画状态。

继承

构造函数

构造函数

ts
new Animation(): Animation;

返回

Animation

继承自

BaseObject.constructor

属性

hashCode

ts
readonly hashCode: number;

定义于: core/BaseObject.ts:156

分配给此实例的唯一标识号。

继承自

BaseObject.hashCode


timeScale

ts
timeScale: number;

定义于: animation/Animation.ts:50

所有动画的播放速度。 [0: 停止播放, (0~1): 慢速播放, 1: 正常播放, (1~N): 快速播放]

默认值

ts
1.0

访问器

animationConfig

Getter 签名

ts
get animationConfig(): AnimationConfig;

定义于: animation/Animation.ts:882

一个可以快速使用的动画配置实例。

返回

AnimationConfig


animationNames

Getter 签名

ts
get animationNames(): readonly string[];

定义于: animation/Animation.ts:845

所有动画数据的名称

返回

readonly string[]


animations

Getter 签名

ts
get animations(): Record<string, AnimationData>;

定义于: animation/Animation.ts:855

所有的动画数据。

返回

Record<string, AnimationData>

Setter 签名

ts
set animations(value: Record<string, AnimationData>): void;

定义于: animation/Animation.ts:858

参数
参数类型
valueRecord<string, AnimationData>
返回

void


isCompleted

Getter 签名

ts
get isCompleted(): boolean;

定义于: animation/Animation.ts:818

检查是否所有的动画状态均已播放完毕。

返回

boolean


isPlaying

Getter 签名

ts
get isPlaying(): boolean;

定义于: animation/Animation.ts:801

检查是否有动画状态正在播放

返回

boolean


lastAnimationName

Getter 签名

ts
get lastAnimationName(): string;

定义于: animation/Animation.ts:835

上一个播放的动画状态名称

返回

string


lastAnimationState

Getter 签名

ts
get lastAnimationState(): AnimationState;

定义于: animation/Animation.ts:894

上一个播放的动画状态

返回

AnimationState

方法

advanceTime()

ts
advanceTime(passedTime: number): void;

定义于: animation/Animation.ts:168

Internal

参数

参数类型
passedTimenumber

返回

void


fadeIn()

ts
fadeIn(
   animationName: string, 
   fadeInTime: number, 
   playTimes: number, 
   layer: number, 
   group: string, 
   fadeOutMode: AnimationFadeOutMode): AnimationState;

定义于: animation/Animation.ts:542

淡入播放指定的动画。

参数

参数类型默认值描述
animationNamestringundefined动画数据名称。
fadeInTimenumber-1.0淡入时间。 [-1: 使用动画数据默认值, [0~N]: 淡入时间 (以秒为单位)] (默认: -1)
playTimesnumber-1播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)
layernumber0混合图层,图层高的动画状态会优先获取混合权重,当混合权重分配总和超过 1.0 时,剩余的动画状态将不能再获得权重分配。 (默认: 0)
groupstringnull混合组名称,该属性通常用来指定多个动画状态混合时的相互替换关系。 (默认: null)
fadeOutModeAnimationFadeOutModeAnimationFadeOutMode.SameLayerAndGroup淡出模式,该属性通常用来指定多个动画状态混合时的相互替换模式。 (默认: AnimationFadeOutMode.SameLayerAndGroup)

返回

AnimationState

播放的动画状态。

示例

ts
    armature.animation.fadeIn("walk", 0.3, 0, 0, "normalGroup").resetToPose = false;
    armature.animation.fadeIn("attack", 0.3, 1, 0, "attackGroup").resetToPose = false;

getBlendState()

ts
getBlendState(
   type: string, 
   name: string, 
   target: BaseObject): BlendState;

定义于: animation/Animation.ts:725

Internal

参数

参数类型
typestring
namestring
targetBaseObject

返回

BlendState


getState()

ts
getState(animationName: string, layer: number): AnimationState;

定义于: animation/Animation.ts:757

获取指定的动画状态。

参数

参数类型默认值描述
animationNamestringundefined动画状态名称。
layernumber-1查找动画状态的层级。 [-1: 查找所有层级, [0~N]: 指定层级] (默认: -1)

返回

AnimationState

示例

ts
    armature.animation.play("walk");
    let walkState = armature.animation.getState("walk");
    walkState.timeScale = 0.5;

getStates()

ts
getStates(): readonly AnimationState[];

定义于: animation/Animation.ts:790

获取所有的动画状态

返回

readonly AnimationState[]


gotoAndPlayByFrame()

ts
gotoAndPlayByFrame(
   animationName: string, 
   frame: number, 
   playTimes: number): AnimationState;

定义于: animation/Animation.ts:603

从指定帧开始播放指定的动画。

参数

参数类型默认值描述
animationNamestringundefined动画数据名称。
framenumber0播放开始的帧数。
playTimesnumber-1播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)

返回

AnimationState

播放的动画状态。


gotoAndPlayByProgress()

ts
gotoAndPlayByProgress(
   animationName: string, 
   progress: number, 
   playTimes: number): AnimationState;

定义于: animation/Animation.ts:636

从指定进度开始播放指定的动画。

参数

参数类型默认值描述
animationNamestringundefined动画数据名称。
progressnumber0.0开始播放的进度。
playTimesnumber-1播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)

返回

AnimationState

播放的动画状态。


gotoAndPlayByTime()

ts
gotoAndPlayByTime(
   animationName: string, 
   time: number, 
   playTimes: number): AnimationState;

定义于: animation/Animation.ts:574

从指定时间开始播放指定的动画。

参数

参数类型默认值描述
animationNamestringundefined动画数据名称。
timenumber0.0播放开始的时间。 (以秒为单位)
playTimesnumber-1循环播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)

返回

AnimationState

播放的动画状态。


gotoAndStopByFrame()

ts
gotoAndStopByFrame(animationName: string, frame: number): AnimationState;

定义于: animation/Animation.ts:690

在指定帧停止指定动画的播放

参数

参数类型默认值描述
animationNamestringundefined动画数据名称。
framenumber0停止的帧数。

返回

AnimationState

播放的动画状态。


gotoAndStopByProgress()

ts
gotoAndStopByProgress(animationName: string, progress: number): AnimationState;

定义于: animation/Animation.ts:714

在指定的进度停止指定的动画播放。

参数

参数类型默认值描述
animationNamestringundefined动画数据名称。
progressnumber0.0停止进度。

返回

AnimationState

播放的动画状态。


gotoAndStopByTime()

ts
gotoAndStopByTime(animationName: string, time: number): AnimationState;

定义于: animation/Animation.ts:666

在指定时间停止指定动画播放

参数

参数类型默认值描述
animationNamestringundefined动画数据名称。
timenumber0.0停止的时间。 (以秒为单位)

返回

AnimationState

播放的动画状态。


hasAnimation()

ts
hasAnimation(animationName: string): boolean;

定义于: animation/Animation.ts:780

检查是否包含指定的动画数据

参数

参数类型描述
animationNamestring动画数据名称。

返回

boolean


init()

ts
init(armature: Armature): void;

定义于: animation/Animation.ts:157

Internal

参数

参数类型
armatureArmature

返回

void


play()

ts
play(animationName: string, playTimes: number): AnimationState;

定义于: animation/Animation.ts:483

播放指定动画。

参数

参数类型默认值描述
animationNamestringnull动画数据名称。 (如果未设置,则播放默认动画,或将暂停状态切换为播放状态,或重新播放之前播放的动画)
playTimesnumber-1循环播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)

返回

AnimationState

播放的动画状态。

示例

ts
    armature.animation.play("walk");

playConfig()

ts
playConfig(animationConfig: AnimationConfig): AnimationState;

定义于: animation/Animation.ts:320

Beta

通过指定的动画配置来播放动画。 该 API 仍在实验阶段,使用时可能遭遇 bug 或稳定性或兼容性问题。

参数

参数类型描述
animationConfigAnimationConfig动画配置。

返回

AnimationState

播放的动画状态。


reset()

ts
reset(): void;

定义于: animation/Animation.ts:272

清除所有的动画状态。

返回

void


returnToPool()

ts
returnToPool(): void;

定义于: core/BaseObject.ts:167

清除该实例的所有数据并将其返还对象池。

返回

void

继承自

BaseObject.returnToPool


stop()

ts
stop(animationName: string): void;

定义于: animation/Animation.ts:292

暂停指定动画状态的播放。

参数

参数类型默认值描述
animationNamestringnull动画状态名称。 (如果未设置,则暂停所有动画)

返回

void


borrowObject()

ts
static borrowObject<T>(objectConstructor: () => T): T;

定义于: core/BaseObject.ts:136

从对象池中获取特定类的实例。

类型参数

类型参数
T extends BaseObject

参数

参数类型描述
objectConstructor() => T特定的类。

返回

T

继承自

BaseObject.borrowObject


clearPool()

ts
static clearPool(objectConstructor: typeof BaseObject): void;

定义于: core/BaseObject.ts:111

清除特定对象池的缓存实例。

参数

参数类型默认值描述
objectConstructortypeof BaseObjectnull特定的类。 (不设置则清除所有缓存的实例)

返回

void

继承自

BaseObject.clearPool


setMaxCount()

ts
static setMaxCount(objectConstructor: typeof BaseObject, maxCount: number): void;

定义于: core/BaseObject.ts:72

设置特定对象池的最大缓存数量。

参数

参数类型描述
objectConstructortypeof BaseObject特定的类。 (不设置则设置所有对象池的最大缓存数量)
maxCountnumber最大缓存数量。

返回

void

继承自

BaseObject.setMaxCount


toString()

ts
static toString(): string;

定义于: animation/Animation.ts:39

返回

string

重写了

BaseObject.toString

Released under the MIT License.