I have a vector with some nodes, but when i want get if any of this nodes have a touch i have problems
Point touchPoint = Director::getInstance()->convertToGL(touch->getLocationInView());
for(auto node: this->nodes){
touchPoint = node->convertToWorldSpace(touchPoint);
Rect rect = node->getBoundingBox();
if(rect.containsPoint(touchPoint))
{
//do stuff
}
}
Inside your for loop, change to
auto nodeTouchPoint = node->getParent()->convertToNodeSpace(touchPoint);
Rect rect = node->getBoundingBox();
if(rect.containsPoint(nodeTouchPoint))
{
//do stuff
}
You were assigning to touchPoint every loop, which changed it for the next loop. Also the point has to be converted to the same node space as the node you are testing you are testing, which requires using the node’s parent to do the conversion.
1 Like