快速連結

顯示具有 TypeScript 標籤的文章。 顯示所有文章
顯示具有 TypeScript 標籤的文章。 顯示所有文章

2022年2月10日

使用EventHandler在CocosCreator面板上拉取node函式

紅框圈起來的就是本次文章重點!
這次的範例是Animation自動播放,然後取得clip時間來呼叫結束函式。
當然也可以進入動畫編輯器,插入事件來呼叫結束函式。

2021年12月7日

[筆記]複數個Spine物件不同時間出現,動畫要一致

規格需求:
  • 第二個Spine物件,動畫要跟第一個出現的Spine物件,動畫要一致
  • Spine動畫修改animationStart時間時,會有一個先從頭開始播再直接跳到指定時間的Bug。故使用addAnimation + delay時間來控一下這個狀況。
  • Spine動畫修改animationStart時間後,每次loop都會從指定的Start time開始播放,因此第一次不要Loop,等播完一次後再打開Loop。

public PlayLoopAnim(startTime: number){
    if (this.isBingoTime)
       return;
    if (startTime > 0){
       let entry: sp.spine.TrackEntry = this.spine.addAnimation(0, "Loop", false, 0.1);
       entry.animationStart = startTime + 0.1;    //Delay時間
       this.spine.setCompleteListener(this.OnPlayLoopOnceEnd.bind(this));
    }else{            
       this.spine.addAnimation(0, "Loop", true);
    }
}

private OnPlayLoopOnceEnd(){
   this.spine.setCompleteListener(null);
   let entry: sp.spine.TrackEntry = this.spine.addAnimation(0, "Loop", true);
   entry.animationStart = 0;
}

2021年10月15日

[筆記]比較UTC時間

new Date是非常好用的語法,不管是給UTC時間、還是地區時間,都可以幫你無痛轉成UTC的時間。
比較也是很簡單!直接做比較運算子就好!

let nowDate: Date = new Date();  
let endDate: Date = new Date( "2021-10-15T12:00:00+00:00");
let myDate: Date = new Date( "2021-10-15T16:22:00");
console.log(nowDate);
console.log(endDate);
console.log(myDate);
if (nowDate > endDate){
    console.log("Bigger");
}else{
    console.log("Smaller");
}
if (nowDate > myDate){
    console.log("Bigger");
}else{
    console.log("Smaller");
}
結果:
[LOG]: nowDate: "2021-10-15T08:22:47.110Z" [LOG]: endDate: "2021-10-15T12:00:00.000Z" [LOG]: myDate: "2021-10-15T08:22:00.000Z" [LOG]: nowDate vs endDate => "Smaller" [LOG]: nowDate vs myDate => "Bigger"

2021年9月2日

在typeScript使用namespace

今天要來講解在cocosCreator中,使用TypeScript來做namespace的實例,以及我遇到的小狀況。 以下就是實際code: