how Xcode automatically remove skspritenode form its parent's node

落花浮王杯 提交于 2019-12-04 17:38:27

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!