[Cocos Creator] 獲取spine動畫精確外邊框

 

// TS
// 參考引擎代碼
GetSpineWorldRect(spine: sp.Skeleton): cc.Rect {
    let rect = cc.rect();
    let hasData = false;
    if (spine) {
        if (spine['_skeleton']) {
            let offset = {
                x: 0,
                y: 0,
                set: function (x: number, y: number) {
                    this.x = x;
                    this.y = y;
                }
            }
            let size = {
                x: 0,
                y: 0,
                set: function (x: number, y: number) {
                    this.x = x;
                    this.y = y;
                }
            }
            let tmp = new Array();
            spine['_skeleton'].getBounds(offset, size, tmp);
            rect.x = offset.x;
            rect.y = offset.y;
            rect.width = size.x;
            rect.height = size.y;
            hasData = true;
        }
    }
    if (!hasData || (rect.x == 0 && rect.y == 0 && rect.width == 0 && rect.height == 0)) {
        rect.x = -50;
        rect.y = -50;
        rect.width = 100;
        rect.height = 100;
    }
    return rect;
}

參考引擎代碼和斷點數據結構

參考

https://blog.csdn.net/Pan_mouren/article/details/93500860

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章