快速連結

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月27日

[筆記][Cocoscreator]2D Sprite/Label在3D模型上渲染(2.4.3)

如果要達成上圖效果,在3.0.0版本後就有cc.RenderRoot2D可以使用,直接在Label上或是Sprite上Add Component就好。詳細可以見官網!
但是3版以前的並沒有這麼支援3D的功能!
在我一番搜尋+瞎貓碰到死耗子的狀況,終於搞定了這個功能。
下收做法:

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日

[筆記]讓金幣依照菱形圖案去跳舞



        private List CoinPos = new List();
        private void CreateCoinPos()
        {
            Vector3 offset = new Vector3(0, 20, 0);
            CoinPos.Clear();
            int _Diameter = 4;
            int _Distance = 60;
            for (int x = -_Diameter; x < _Diameter + 1; x++)
            {
                int r = Math.Abs(x % 2);
                int dis = _Diameter - Math.Abs(x);
                for (int y = -dis; y < dis + 1; y++)
                {
                    int ry = Math.Abs(y % 2);
                    if (ry != r)
                        continue;

                    Vector3 _Pos = new Vector3(x * _Distance, y * _Distance, 0);
                    _Pos += offset;
                    CoinPos.Add(_Pos);
                }
            }
            CoinPos.Sort(delegate(Vector3 a, Vector3 b)
            {
                float ad = Vector3.Distance(a, Vector3.zero);
                float bd = Vector3.Distance(b, Vector3.zero);
                if (ad < bd) return -1;
                if (ad > bd) return 1;
                return 0;
            });
        }
        public void DropCoin(int Length)
        {

        }

在typeScript使用namespace

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

2021年5月15日

渲染順序 Rendering order

最近有同事在研究NGUI與UGUI的渲染順序關係(假如用同一個camera下),不過今天不是想講這個議題,而是來講講渲染順序。
當然也是有參考一些網路上的文章,本文主要是我看完後吸收到的結論。

以下圖片是實作渲染順序,如果看不懂…請再跟我說。(以下皆使用2017.4.3f1)