Cocos Creator 動畫控制

//即使playOnLoad=true,也必須調用play函數播放一個動畫,currentClip屬性纔會賦值
let animation=this.getComponent(cc.Animation);
animation.playOnLoad=true;
cc.log(animation.currentClip);//ouput: null
animation.play("idle");
cc.log(animation.currentClip.name);//ouput: idle

//每幀都調用play方法播放一個動畫時,必須判斷要播放的剪輯是否已是當前剪輯,否則會一直播放停止在第一幀
if(animation.currentClip.name!="walk"){
      animation.play("walk");
}

let animationState=animation.play("idle");
animationState.time;//動畫播放的時間(注意:播放循環的的動畫剪輯時,播放完成一遍後不會重置0)

偵聽循環的動畫剪輯播放完成

let animation=this.getComponent(cc.Animation);
let animationState=animation.play("idle");
animationState.wrapMode=cc.WrapMode.Loop;
animationState.repeatCount=0;//設置循環的次數,0表示只播放一次(則不需要去設置wrapMode)
animation.on("finished",this.onFinished,this);
//private onFinished():void{}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章