Hi. I’m working on a cocos2dx c++ app using version 3.7. I’m having issues referencing a csb file the that is referenced in a cocos studio (ccs) file. The project has been exported for cocos2dx. The artist has created a Node with some graphics on it. He also has referenced a csd file this node pulls in. The problem is when I try to reference this file in cocos2dx c++ The parent node of this csb doesn’t recognize it. Any ideas? My code is pretty basic. auto node = rootNode->getChildByName(“someNodeRefrencingACsbFile”);
If I understand your problem well, you are able to load the CSB file into a node (the rootNode) from which you want to retrieve a child by its name, but the child is not found. Is this correct?
Just in case, loading a CSB is done like this:
// Load a Cocos Studio scene from CSB file into a Node
rootNode = CSLoader::createNode("MainScene.csb"); // rootNode is a member variable of type cocos2d::Node*
this->addChild(rootNode); // Add the node to the current scene
After you have your Cocos Studio scene loaded into a node, you can retrieve references of elements of the scene in this way:
// Get a child reference from rootNode.
auto enemy1 = rootNode->getChildByName("enemy_1");
/* Be careful if your scene has several levels of parenting. Say, you have a "GUI_layer" which has a child called "pause_button". Retrieving a reference of this button is done this way:
*/
auto guiLayer = rootNode->getChildByName("GUI_layer");
auto pauseButton = guiLayer->getChildByName("pause_button");
But if the specified child is not found after calling to getChildByName, you get a nullptr. If you get nullptr, check if you wrote the child’s name correctly, or if you need to retrieve first a reference to the parent of the node you are looking for, such as I shown at the pause button example.
1 Like