3

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.

IMustCode
  • 109
  • 8

2 Answers2

6
if ( [ myNode.children indexOfObject:sprite ] == NSNotFound ) {

     // you can add the code here

}
oopology
  • 1,072
  • 1
  • 10
  • 19
1

There's so many ways:

1) try to get child

if (![layer getChild:sprite]) {
   // Your code
}

2) try to get child by tag

if (![layer getChildByTag:spriteTag]) {
   // Your code
}

3) Check if sprite is on children array (like @oopology answer)

if ([layer.children indexOfObject:sprite] == NSNotFound) {
   // Your code
}
Bivis
  • 1,320
  • 1
  • 10
  • 24