版本: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)
}

版本:Cocos Creater 3.7.0

    start() {
        let skeletalAnimation = this.node.getComponent(SkeletalAnimation);
        skeletalAnimation.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
    }

    onAnimationFinished(type:Animation.EventType, state:SkeletalAnimationState){
    }

Logo

这里是一个专注于游戏开发的社区,我们致力于为广大游戏爱好者提供一个良好的学习和交流平台。我们的专区包含了各大流行引擎的技术博文,涵盖了从入门到进阶的各个阶段,无论你是初学者还是资深开发者,都能在这里找到适合自己的内容。除此之外,我们还会不定期举办游戏开发相关的活动,让大家更好地交流互动。加入我们,一起探索游戏开发的奥秘吧!

更多推荐