如何获得一个Node的BoundingBox
2个回答
展开全部
自己写了2个函数,递归获取Node的BoundingBox和ContentSize,用着貌似没什么Bug。。。 onlyTexture参数的意思是只统计贴图占用的空间
Rect getBoundingBoxRecursive(Node *node, bool onlyTexture = true) {
CCAssert(node != nullptr, "node can't be null");
Rect nodeRect = node->getBoundingBox();
nodeRect.origin = node->convertToWorldSpace(Vec2::ZERO);
for_each(node->getChildren().begin(), node->getChildren().end(), [&](Node* subNode) {
Rect subNodeRect;
subNodeRect = getBoundingBoxRecursive(subNode);
if (onlyTexture && nodeRect.size.equals(Size::ZERO)) {
nodeRect.origin = subNodeRect.origin;
}
nodeRect.merge(subNodeRect);
});
return nodeRect;
}
Vec2 getContentSizeRecursive(Node *node, bool onlyTexture = true) {
return getBoundingBoxRecursive(node, onlyTexture).size;
更多内容可参考资料http://www.viiboo.cn
Rect getBoundingBoxRecursive(Node *node, bool onlyTexture = true) {
CCAssert(node != nullptr, "node can't be null");
Rect nodeRect = node->getBoundingBox();
nodeRect.origin = node->convertToWorldSpace(Vec2::ZERO);
for_each(node->getChildren().begin(), node->getChildren().end(), [&](Node* subNode) {
Rect subNodeRect;
subNodeRect = getBoundingBoxRecursive(subNode);
if (onlyTexture && nodeRect.size.equals(Size::ZERO)) {
nodeRect.origin = subNodeRect.origin;
}
nodeRect.merge(subNodeRect);
});
return nodeRect;
}
Vec2 getContentSizeRecursive(Node *node, bool onlyTexture = true) {
return getBoundingBoxRecursive(node, onlyTexture).size;
更多内容可参考资料http://www.viiboo.cn
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
展开全部
CCRect CCArmature::boundingBox()
{
float minx, miny, maxx, maxy = 0;
bool first = true;
CCRect boundingBox = CCRectMake(0, 0, 0, 0);
CCObject *object = NULL;
CCARRAY_FOREACH(m_pChildren, object)
{
if (CCBone *bone = dynamic_cast<CCBone *>(object))
{
CCRect r = bone->getDisplayManager()->getBoundingBox();
if (r.size.width == 0 || r.size.height == 0)
continue;
if(first)
{
minx = r.getMinX();
miny = r.getMinY();
maxx = r.getMaxX();
maxy = r.getMaxY();
first = false;
}
else
{
minx = r.getMinX() < boundingBox.getMinX() ? r.getMinX() : boundingBox.getMinX();
miny = r.getMinY() < boundingBox.getMinY() ? r.getMinY() : boundingBox.getMinY();
maxx = r.getMaxX() > boundingBox.getMaxX() ? r.getMaxX() : boundingBox.getMaxX();
maxy = r.getMaxY() > boundingBox.getMaxY() ? r.getMaxY() : boundingBox.getMaxY();
}
boundingBox.setRect(minx, miny, maxx - minx, maxy - miny);
}
}
return CCRectApplyAffineTransform(boundingBox, nodeToParentTransform());
}
{
float minx, miny, maxx, maxy = 0;
bool first = true;
CCRect boundingBox = CCRectMake(0, 0, 0, 0);
CCObject *object = NULL;
CCARRAY_FOREACH(m_pChildren, object)
{
if (CCBone *bone = dynamic_cast<CCBone *>(object))
{
CCRect r = bone->getDisplayManager()->getBoundingBox();
if (r.size.width == 0 || r.size.height == 0)
continue;
if(first)
{
minx = r.getMinX();
miny = r.getMinY();
maxx = r.getMaxX();
maxy = r.getMaxY();
first = false;
}
else
{
minx = r.getMinX() < boundingBox.getMinX() ? r.getMinX() : boundingBox.getMinX();
miny = r.getMinY() < boundingBox.getMinY() ? r.getMinY() : boundingBox.getMinY();
maxx = r.getMaxX() > boundingBox.getMaxX() ? r.getMaxX() : boundingBox.getMaxX();
maxy = r.getMaxY() > boundingBox.getMaxY() ? r.getMaxY() : boundingBox.getMaxY();
}
boundingBox.setRect(minx, miny, maxx - minx, maxy - miny);
}
}
return CCRectApplyAffineTransform(boundingBox, nodeToParentTransform());
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询