如何在cocos2d中的某个点获取节点?在SpriteKit中,我可以执行以下操作:
[parentNode nodesAtPoint:aPoint];
并返回一个包含该位置所有节点的数组。在Cocos2d(3)中有类似的东西吗?
答案 0 :(得分:3)
我不认为cocos2d有一个方法(如果我错了,请纠正我)。 我通过触摸事件检查某个节点的方式是这样的:
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
}
}
}