[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

你可能感兴趣的:(TS,js,cocoscreator)