最近在研究使用cocosStudio来编译游戏的场景和UI界面,发现可以提高编辑的效率。但是导入文件的时候会遇到一些问题,总结下解决方法。
首先:
关于cocosStudio UI编辑器的使用和导出需要用的JSon文件,这方面百度资料都是有的。
在你要使用的类中,头文件加入
#include "HelloWorldScene.h"
#include "cocos2d.h"
#include "editor-support/cocostudio/CCSGUIReader.h"
#include "ui/UILayout.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "extensions/cocos-ext.h "
在加入命名空间:
USING_NS_CC;
using namespace cocostudio;
using namespace ui;
程序上的引用代码为:
auto myLayout = dynamic_cast<Layout*>(cocostudio::GUIReader::shareReader()->widgetFromJsonFile("NewUI_1.json"));
this->addChild(myLayout);
Button* rightBtn = (Button*)Helper