如何获得一个Node的BoundingBox
1个回答
推荐于2016-02-06
展开全部
自己写了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;
}
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;
}
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询