Reputation: 109
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.
Upvotes: 3
Views: 723
Reputation: 1408
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
}
Upvotes: 1
Reputation: 1072
if ( [ myNode.children indexOfObject:sprite ] == NSNotFound ) {
// you can add the code here
}
Upvotes: 6