CCNode removeFromParentAndCleanup is a function in the Cocos2d-x game engine library, which allows the removal of a node from its parent and deletes its related resources to free up memory. The syntax of this function is:
void removeFromParentAndCleanup(bool cleanup)
where the parameter "cleanup" indicates whether to delete the related resources or not.
Example 1:
auto sprite = Sprite::create("sprite_image.png"); this->addChild(sprite);
//... some code
sprite->removeFromParentAndCleanup(true);
In this example, a sprite is added as a child to the current node, and later, it is removed from its parent and also deletes the sprite's related resources.
Example 2:
auto label = Label::createWithTTF("Hello World!", "fonts/arial.ttf", 24); this->addChild(label);
In this example, a label is added as a child to the current node, and based on a condition, it is removed with the related resources or without them.
Overall, the removeFromParentAndCleanup function is a useful utility function in the Cocos2d-x game engine library to keep the memory consumption under control.
C++ (Cpp) CCNode::removeFromParentAndCleanup - 17 examples found. These are the top rated real world C++ (Cpp) examples of CCNode::removeFromParentAndCleanup extracted from open source projects. You can rate examples to help us improve the quality of examples.