I'm new in objectif-c and sprite-kit development (but not in programming). So I'm starting the Apple's Spri. The app works perfectly, except that the nodes representing the rocks are automatically removed form its parent when rocks fall through the bottom of the scene. This, without implementing the -(void)didSimulatedPhysics method :
- (void)didSimulatedPhysics
{
[self enumerateChildNodesWithName:@"rock" usingBlock:^(SKNode *node, BOOL *stop) {
if (node.position.y < 0)
[node removeFromParent];
}];
}
I can see that with the nodes counter shown on the screen : it doesn't increase with the number of rocks. So my question is : is Xcode manage the removeFromParent method for my program ? if yes, could you tell me the option to disable. I try to sert ARC to NO, but it doesn't make any change.
I hope my message is clear. If not, please tell me. Thanks in advance for your answer.
Raphael
I can see that with the nodes counter shown on the screen : it doesn't increase with the number of rocks.
This is because Sprite Kit counts only "rendered" nodes (ie nodes on screen) by default. To see culled nodes, you have to enable an additional, undocumented debug flag:
[self.scene.view setValue:@(YES) forKey:@"_showsCulledNodesInNodeCount"];
Alternatively, to get the true node count of a node, such as the scene, add this where you want to log the node count:
NSLog(@"node count: %u", (unsigned int)self.children.count);
In other words: if you don't remove a node from its parent, Sprite Kit will not do this for automatically under no circumstances. It will however clear up the node graph of the old scene when presenting a new scene, provided there aren't any retain cycles (commonly found when holding a strong reference to a parent or sibling node in a custom SKNode subclass).
Before you order an SKView to present a scene, you must be calling these lines:
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES; // This is what shows the node count.
From Apple's documentation, the showsNodeCount
property is described as:
A Boolean value that indicates whether the view displays the count of the nodes visible in the scene.
Hence, Sprite Kit does not remove them from their parent. If those nodes were to come back into the view's bounds, they would in turn increase this node count.
来源:https://stackoverflow.com/questions/22811296/how-xcode-automatically-remove-skspritenode-form-its-parents-node