更换节点的父节点

 

 

1 child->retain();//引用计数+1
2 
3 child->removeFromParent(); 
4 
5 root->addChild();
6 
7 child->release(); //引用计数-1

需要注意的是retain()和release(),如果在卸载节点前不调用retain的话会导致报错

CCAssert( child->m_pParent == NULL, "child already added. It can't be added again"); 

 

release()要和retain()成对使用,否则会引起内存泄露

posted @ 2014-06-09 20:02  Reise  阅读(451)  评论(0编辑  收藏  举报