版本:Cocos Creater 2.4.10
var animation = this.node.getComponent(cc.Animation);
// 注册
animation.on('play', this.onPlay, this);
animation.on('stop', this.onStop, this);
animation.on('lastframe', this.onLastFrame, this);
animation.on('finished', this.onFinished, this);
animation.on('pause', this.onPause, this);
animation.on('resume', this.onResume, this);
// 取消注册
animation.off('play', this.onPlay, this);
animation.off('stop', this.onStop, this);
animation.off('lastframe', this.onLastFrame, this);
animation.off('finished', this.onFinished, this);
animation.off('pause', this.onPause, this);
animation.off('resume', this.onResume, this);
版本:Cocos Creater 2.4.0
this.ani.on(AnimationComponent.EventType.FINISHED, () => {
//结束执行的方法
poolManager._instance.putNode(this.node);
});
骨骼动画 SkeletalAnimation
版本:Cocos Creater 3.3.0
ani: SkeletalAnimation = null!;
//获取
this.ani = this.node.getChildByName(`Player`).getComponent(SkeletalAnimation);
//动画结束会调用 onMoveStateEnd() 方法
this.ani.getState(`Roll`).on(AnimationComponent.EventType.FINISHED, this.onMoveStateEnd, this);
onMoveStateEnd() {
this.playAni(MoveState.Run)
}