2013-03-14 38 views

回答

5

当你有了孩子,你需要为了做一个typecast来检查它是否是一个精灵或层:

for(int i = 0; i < myNode->getChildren()->count(); i++) 
{ 
    CCNode *child = myNode->getChildren()->objectAtIndex(i); 
    CCSprite* s = dynamic_cast<CCSprite*>(child); 
    if(s != 0) { 
     ... 
    } 
} 
1

这是另一个样品可以帮助:

Vector<Node*> allNodes=this->getChildren(); 
for(auto& node : allNodes){ 
    if(dynamic_cast<Sprite*>(node)){ //It is Sprite 
     Sprite *target=dynamic_cast<Sprite*>(node); 
     //Do whatever you like 
    } 
} 
相关问题