cocos2d-iphonecclayer

how to determine if a sprite is in a layer


Sorry if this sounds quite trivial. I am just not getting it. How can one determine if a particular sprite is already in a layer? Basically, I need to check this before determining whether to add it to the layer or not.


Solution

  • if ( [ myNode.children indexOfObject:sprite ] == NSNotFound ) {
    
         // you can add the code here
    
    }