xcode 以后如何移除孩子?(cocos2d)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2891696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I remove a child later? (cocos2d)
提问by RexOnRoids
I added a child like this inside of a CCLayer:
我在 CCLayer 中添加了一个这样的孩子:
[self addChild:object1];
Later on I want to remove that object from the children. Ummm so how do I do that? Thanks.
稍后我想从孩子们身上移除那个物体。嗯,那我该怎么做呢?谢谢。
采纳答案by LearnCocos2D
Your question leads me to believe you don't know the cocos2d API reference: http://www.cocos2d-iphone.org/api-ref/
你的问题让我相信你不知道 cocos2d API 参考:http: //www.cocos2d-iphone.org/api-ref/
To remove object1 simply use this:
要删除 object1,只需使用以下命令:
[self removeChild:object1 cleanup:YES];
If you don't keep a reference of object1 around you can remove it by tag, which means you'll have to give it a tag first:
如果您不保留对 object1 的引用,则可以通过标签将其删除,这意味着您必须先给它一个标签:
object1.tag = 123; // just any arbitrary number
[self addChild:object1];
To remove it:
要删除它:
[self removeChildByTag:123 cleanup:YES];
I've added this Q&A to my cocos2d FAQ, please find more details to this answer here: http://www.learn-cocos2d.com/knowledge-base/cocos2d-iphone-faq/learn-cocos2d-public-content/manual/cocos2d-general/14824-how-to-remove-a-child-from-the-nodescenelayer
我已将此问答添加到我的 cocos2d 常见问题解答中,请在此处找到此答案的更多详细信息:http: //www.learn-cocos2d.com/knowledge-base/cocos2d-iphone-faq/learn-cocos2d-public-content/手册/cocos2d-general/14824-how-to-remove-a-child-from-the-nodescenelayer
回答by deanWombourne
Try the removeChildmethod?
试试removeChild方法?