How can I get the nodes at a certain point in cocos2d? In SpriteKit I can do the following:
[parentNode nodesAtPoint:aPoint];
and it returns an array with all the nodes at that position. Is there something similar in Cocos2d (3)?
How can I get the nodes at a certain point in cocos2d? In SpriteKit I can do the following:
[parentNode nodesAtPoint:aPoint];
and it returns an array with all the nodes at that position. Is there something similar in Cocos2d (3)?
I don't think cocos2d has a method for this(correct me if I am wrong). The way I check for the node's which are at a certain point with a touch event is like this:
CGPoint location = [touch locationInView:[touch view]];
for (CCNode node in [parent children]) //if parent is the current scene/layer with the objects to check
{
//if you want 1 type of class
if (node isKindOfClass:[EnemyController class] ) {
if (CGRectContainsPoint(node.boundingBox, location)) {
//your code here, for example:
[yourArray addObject:node]; //if you want the objects in a predefined array
break; //break if you only want the first object that comes along
}
}
}