[Cocos Creator] 获取spine动画精确外边框
程序员文章站
2024-03-16 16:44:58
...
// 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;
}
参考引擎代码和断点数据结构
参考
上一篇: box2d collision
下一篇: 1296: 近似计算