CSLoader turns all children to Node

Hello, I’m using cocos2dx-3.10 to load a CSB published by Cocos Studio 3.10 with CSLoader::createNode(std::string filename). In the CSB I put in some widgets like Panel, Label… but in runtime, everything turned out to be Node, and I cannot cast them back to use them. Can you verify this for me, please?

You should be able to cast to them fine. It is true that they are of class type node but there should be no problem using static_cast on them. here’s and example. This code wasn’t tested but should work

        #include "HelloWorldScene.h"
        #include "cocostudio/CocoStudio.h"
        #include "ui/CocosGUI.h"
        
        USING_NS_CC;
        
        using namespace cocostudio::timeline;

        // Create an anonymous namespace for you nodes inside the csb file 
       namespace {
            cocos2d::ui:PageView* pageview_ = nullptr;
        }
        
        Scene* HelloWorld::createScene()
        {
            // 'scene' is an autorelease object
            auto scene = Scene::create();
            
            // 'layer' is an autorelease object
            auto layer = HelloWorld::create();
        
            // add layer as a child to scene
            scene->addChild(layer);
        
            // return the scene
            return scene;
        }
        
        // on "init" you need to initialize your instance
        bool HelloWorld::init()
        {
            //////////////////////////////
            // 1. super init first
            if ( !Layer::init() )
            {
                return false;
            }
            
            auto rootNode = CSLoader::createNode("MainScene.csb");
            addChild(rootNode);

            pageview_ = static_cast<cocos2d::ui::PageView*>(rootNode->getChildByName("page_view"));
        
            return true;
        }

if static_cast doesn’t work, you can also use dynamic_cast or reinterpret_cast as a last resort.

PS: A Panel widget in Cocos Studio = cocos2d::ui::Layout*
PSS: A Label Widget in Cocos Studio = cocos2d::ui::Text*

Thank you for your reply. I know I should be able to cast them back (used to work on v3.3). But I have run debugged and found that they REAL Node objects, not Node pointer to Widget objects, so any cast will return NULL

what do you mean by “real” Node objects? They should be of type cocos2d::Node*

Here a snippit of code from the cocosstudio 3d test:

    CSSceneSkyBoxTest::CSSceneSkyBoxTest() {
    auto node = CSLoader::createNode("SkyBox.csb");

    addChild(node);

    _camera = static_cast<Camera*>(node->getChildByName("UserCamera_0"));

   ...
}

If your not doing somthing similar to this, then I think you maybe doing somthing wrong. Did you forget to call addChild(node);?

If your just mainly asking why they don’t come in as thier type from CSLoader::createNode(std::string filename) then I think it’s because it’s easier to manage for them. Also, Most people with a heavy CocosStudio Workflow barely need to edit anything @ run time so you don’t need to full object of to be loaded into memory. That would be my guess anyways.