auto sprite = Sprite::create("image.png"); sprite->setTag(1); auto node = Node::create(); node->addChild(sprite); int tagValue = sprite->getTag(); // Retrieves the tag value of the sprite
auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24); label->setTag(2); auto scene = Scene::create(); scene->addChild(label); int tagValue = label->getTag(); // Retrieves the tag value of the labelIn this example, we create a label and set its tag value to 2. We then create a new scene and add the label as a child. Finally, we retrieve the tag value of the label using the getTag method. The getTag method is part of the Cocos2d-x library, specifically the CCNode class.