CCHide or removeFromParent?

CCHide or removeFromParent?
0.0 0


I used to use setVisible(false) when I no longer wanted my sprites to display onscreen, but I have read that it is bad practice, that it still calls draw() on the sprite or something like that. So which is the better practice when you want a sprite to no longer display at the moment, but to display again in the future? Thank you.


Hello, @Isaac
If the sprite you just hided will be using in the near future. It is better to set it’s visible property to false.
At some time, we will use a array to cache a list of sprites, such as bullets, enemies etc. These sprites are created invisible and all added to current scene and the array. When we want to spawn a sprite. we just pick a non-visible one from the array and reset it’s position and make it shows again on screen. This cache method will greatly increase your game performance
You shouldn’t remove it from parent, since it will slow down your game.
The best practice is call CCHide or manually toggle it’s visibility.



Thank you Guanghui. My question was precisely for bullets and enemies. Now the question is whether to use setVisible(bool) or CCHide/CCShow. As of now, each of my enemies and bullets have a pointer to a CCHide and CCShow action. Is it better to have the sprites hold these actions than to use setVisible? I ask because the cocos2d-x page references this article when it comes to optimizations.