Rect getRect(Node* node);
Rect getWorldRect(Node* node);
Rect HelloWorld::getRect(Node* _node)
{
//sprite 也有children
Vector<Node*> &vec = _node->getChildren();
Rect rect1 = getWorldRect(_node);
for (Node* node : vec)
{
Rect rect;
if (node->getChildrenCount() > 0)
{
rect = this->getRect(node);
}
else
{
rect = getWorldRect(node);
}
if ( rect.size.equals(Size::ZERO) )
{
continue;
}
if ( rect1.size.equals(Size::ZERO) )
{
rect1 = rect;
continue;
}
rect1 = rect1.unionWithRect(rect);
}
return rect1;
}
Rect HelloWorld::getWorldRect(Node* _node)
{
Rect rect = _node->getBoundingBox();
Point po = _node->getParent()->convertToWorldSpace( rect.origin );
return Rect(po.x, po.y, rect.size.width, rect.size.height);
}
bool HelloWorld::onTouchBegan(Touch *touch, Event *unused_event)
{
Rect rect = this->getRect( unused_event->getCurrentTarget() );
if ( rect.containsPoint( touch->getLocation() ) )
{
log("11111111111111111");
}
return true;
}
得到最大矩形
最新推荐文章于 2024-06-07 18:25:02 发布