Hi,
I have a custom class that is set in the properties of on 1 of the nodes in Cocos Studio.
Every time I make object of this class I use dynamic_cast like this:
CustomClass* actor = dynamic_cast<CustomClass*>(CSLoader::createNode("CustomClassNode.csb"));
But my problem is that I have a class that inherits from CustomClass, my question is how do I make the constructor of that class using the properties that are set in the .csb file?
You need to register a loaded for each custom class. For example when you have a custom class HeroNode like that:
static cocos2d::Ref* createForLoader() { return HeroNode::create(); }
You need to register the class like that:
cocos2d::CSLoader::getInstance()->registReaderObject(“HeroReader”, &HeroNode::createForLoader);
The reader name must be the custom class name set in Cocos Studio plus “Reader”(e.g. “Hero” in CocosStudio and “HeroReader” for the reader)
I register a reader that’s not the problem, the problem is if I want to have a class that inherits from Hero for example. How do I make a constructor for it?
I think this guide should work : http://cocos2d-x.org/documentation/editors_and_tools/chapter3/HowToCode/CallBack/en/index.html
I have used this approach a while ago, currently it causes problems while loading but I did it mostly like in the guide above.
I don’t know if you need the WidgetCallbackHandlerProtocol for classes which don’t need callbacks, I think it should work without it.