auto node = Node::create(); auto parentNode = node->getParent(); if (parentNode != nullptr) { log("The parent node's tag is: %d", parentNode->getTag()); }
auto sprite = Sprite::create("example.png"); auto parentNode = Node::create(); parentNode->addChild(sprite); auto grandparentNode = sprite->getParent()->getParent(); if (grandparentNode != nullptr) { log("The grandparent node's order is: %d", grandparentNode->getOrderOfArrival()); }This example creates a sprite node and a parent node. The sprite is added as a child to the parent node, which is then added as a child to a new grandparent node. The method retrieves the grandparent node and logs its order of arrival to the console. Package library: Cocos2d-x (cocos2d::Node)