Tag to prefab dynamically and intersect in script

How to give the tag to the specific prefab which is randomly generated in the world. This is the Cocos2dx code snippet. I want to do this in the creator-type script. I want to give each one a different tag. Kindly help.

             count++;
	 demo = Sprite::create(“d1”);
            demo->setPosition(Vec2(362.399170,831.098450));
            demo->setTag(count);
            this->addChild(demo);

if(this->getChildByTag(i)->getBoundingBox().containsPoint(location))

You can rename your generated node using node.name = "", then get it with getChildByName

1 Like