且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Xcode如何自动从其父节点中删除skspritenode

更新时间:2023-02-02 10:12:50


我可以看到屏幕上显示的节点计数器:它不会随着岩石的数量增加

I can see that with the nodes counter shown on the screen : it doesn't increase with the number of rocks.

这是因为Sprite Kit默认只计算渲染节点(即屏幕上的节点)。要查看已淘汰的节点,您必须启用其他未记录的调试标志:

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);

换句话说:如果你没有从父节点中删除节点,Sprite Kit将在任何情况下都不会自动执行此操作。但是,如果没有任何保留周期(通常在自定义SKNode子类中保存对父节点或兄弟节点的强引用时找到),它将在呈现新场景时清除旧场景的节点图。

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).