大侠
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
1023 B

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();
}
}
}