Remove and add again same node

Hello !

I’m wondering if Cocos2d-Html5 (2.2.3) officially support to add then remove and add again some nodes. For example:
-> creating testLayer in global var
-> enter scene1
-> scene1layer.addChild(testLayer);
-> scene1layer.removeChild(testLayer);
-> replace scene to scene2
-> scene2layer.addChild(testLayer);
I mean… I know that testLayer after changing scene still exists in global var but is it ok for cocos or should I forget about adding and removing the same element on different scenes on and on and create new instance each time ? I need this to have user interface same on all scenes so ideally I do not want to create new interface each time but just to remove and add it again as a layer with some other nodes.

Thanks!

Does “cocos” mean “Cocos2d-JSB”?

If you want to use global var in JSB, you need call retain and release.

Hopes to help.
David

It mean Cocos2d-Html5, I’m not using Cocos2d-Html5 2.2.3 with JSB. I will be porting game to Cocos2d-JS 3.0 so then I will take on my attention Your answer, so THX. You answered me indirectly. My question was simplier than You thought. If I use remove - then element is still fully usefull after adding it again or it’s somehow corrupted and should never be used again (so we should create It again and it will look like copy but it’s other instance). From your answer You do not denied to add element again after remove, so I understand It was not point for you to cut the answer for other thing which was global var :slight_smile: