Cocos2dx - How to find if child is sprite or layer?
cocos2d-x
Solution
When you have a child, you need to do a typecast in order to check whether it's a sprite or a layer:
for(int i = 0; i < myNode->getChildren()->count(); i++)
{
CCNode *child = myNode->getChildren()->objectAtIndex(i);
CCSprite* s = dynamic_cast<CCSprite*>(child);
if(s != 0) {
...
}
}
Problem
I have implemented an application in cocos2dx. The issue that i am facing currently is that i am not able to find whether the child is a sprite or a layer as the getChildren() method returns list of CCObjects. Any help appreciated.