Hello everyone.
I am trying to use CocoStudio to make GUI of my game. I am using cocos2dx 3 (3.0rc0, but also trying 3.2rc0) I made GUI, did export and took a JSON file.
Then I tryed to use it in game, following this instruction.
But I can’t find a UIHelper class. Also I tryed this way, but i didn’t have any profit, becouse I didn’t found SceneReader.
So, how I should use .json files from cocostudio in game using cocos2dx 3.x?
UIHelper.h is located in yourProject\cocos2d\cocos\ui
You should be able to include it with #include <ui\UIHelper.h> If not than look at the include-directories of the vs project.
Did you include libCocosStudio? The SceneReader is located in yourProject\cocos2d\cocos\editor-support\cocostudio.
One step after another. Were you able to add libGUI libCocosStudio libExtensions to your project?
Can you see it on the left while working with Visual Studio?
They are from my project, but all of them are located in UIHelper.h.
…
Well, I think I found solution.
VS tell me, that Widget undifined. I’m include “UIWidget.h” and It all builds succsesful.
In cocos2d-x 3.0 C++ you use the sceneReader to load json files. The uihelper could be used for the three methods you posted (personally I do not use UIHelper).
Read a cocostudio scene.
auto scene = cocostudio::SceneReader::getInstance()->createNodeWithSceneFile("publish/Intro.json");
You can add it like this
this->addChild(scene);
You need to include (I thinks that’s all, not 100% sure)
Great thanks you! This way is really true, and I finnaly compile a program. But, exactly, compile != work. So, I faced with one more problem
I export UI, placed it in a directory into my project, create scene with a getInstance()->createNodeWithSceneFile(%filename%);
But I get a run-time error:
In SceneReader class called function createObject
In this function called function getStringValue_json(dict, “classname”) of the DictionaryHelper. This function should return some string, but It returns NULL/
Result of this functions used in strcmp, but it is NULL, so there is runtime error.
(File really exists, if I try to createNodeWithSceneFile of a not-existing file, this function works well and returns NULL)
Wait Wait Wait… You can only read jsons which were created from the Scene Editor with the cocostudio::SceneReader. If you want to read jsons which were created from the UI Editor you need the cocostudio::GUIReader
auto widget = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("ui/livingRoom/livingRoom.json");