I have an array of sprites in sprite kit and in my update method I check to see if these sprites fall off the bottom of the screen. If they do, I remove them from their parent and I remove them from their array..what I am wondering is if they way I am doing it if it is the best practice? Is it going to slow down performance? If so, what is the best way to go about accomplishing this?
Here's my code:
-(void)update:(CFTimeInterval)currentTime {
// Detect when animals fall off bottom of screen
NSMutableArray *animalsToDiscard = [NSMutableArray array];
for (SKSpriteNode* node in animalsArray) {
if (node.position.y < -node.size.height) {
NSLog(@"Remove Animal - Lose Life");
[node removeFromParent];
[animalsToDiscard addObject:node];
}
}
[animalsArray removeObjectsInArray:animalsToDiscard];
}