Jumping to a specific SKNode in node hierarchy

不问归期 提交于 2019-12-05 08:10:05
LearnCocos2D

You can use the advanced search syntax described in the SKNode documentation, under Advanced Searches.

This will search the entire node tree recursively for a node named "SPHERE2", starting from the root node:

SKNode* sphere2 = [root childNodeWithName:@"//SPHERE2"];

If you know the path to a specific node, you can also use that quite easily:

SKNode* triangle3 = [root childNodeWithName:@"/CUBE3/SPHERE2/TRIANGLE3"];

It should be noted if you need those nodes often, you should cache them in a __weak ivar or weak property because searching nodes by name takes a little while.

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