這次的範例是Animation自動播放,然後取得clip時間來呼叫結束函式。
當然也可以進入動畫編輯器,插入事件來呼叫結束函式。
const {ccclass, property} = cc._decorator;
@ccclass
export default class AnimationAutoPlay extends cc.Component {
@property(cc.Animation)
private animation : cc.Animation = null;
@property()
private animationName: string = "";
@property(cc.Component.EventHandler)
private completeEvent: cc.Component.EventHandler = null;
///物件被打開時
public onEnable(){
this.PlayAnim();
}
protected onDisable(): void {
this.PlayAnim();
}
private PlayAnim(){
if(this.animationName.length == 0)
this.animationName = this.animation.defaultClip.name;
this.animation.play(this.animationName, 0);
this.scheduleOnce(this.OnAnimPlayComplete, this.animation.currentClip.duration);
}
public OnAnimPlayComplete(){
if (this.completeEvent){
cc.Component.EventHandler.emitEvents([this.completeEvent]);
}
}
}
沒有留言:
張貼留言
歡迎大家留言提問,我會答的都會盡力回答!
如果太久沒出現回應就是我又忘記回來看留言了TAT