import { _decorator, Component, Node,Animation } from 'cc'; const { ccclass, property } = _decorator; @ccclass('TipsAnimation') export class TipsAnimation extends Component { @property(Animation) m_animation: Animation = null; @property(Node) tips:Node = null; // 添加完成回调函数字段 private finishCallback: Function = null; // 设置动画完成回调 setFinishCallback(callback: Function) { this.finishCallback = callback; } PlayAnimation(){ this.m_animation.hasEventListener(Animation.EventType.FINISHED) || this.m_animation.on(Animation.EventType.FINISHED, this.onFinished, this); this.m_animation.play(); } onStopAnimation(){ this.m_animation.stop(); this.onFinished(); } onFinished(){ // 如果设置了回调,则执行回调,否则默认销毁节点 if (this.finishCallback) { this.finishCallback(this); } else { this.node.destroy(); } } }