1.添加头文件和引用
#include "CocosGUI.h"
#include "cocostudio/CocoStudio.h"
using namespace gui;
using namespace cocostudio;
备注: 需要引用namespace gui 和 cocostudio
namespace gui 包含的所有UI元素为cocostudio界面上拖动的所有元素所在的命名空间中;
cocos2d-x 需要引入cocostudio UI编辑导出后的json, 需要引入namespace cocostudio;
2.在Layer::init()方法中,添加cocostudio 导出的AirPlane.ExportJson json文件,
代码如下:
UILayer* uiLayer = UILayer::create();
auto myLayout = cocostudio::GUIReader::shareReader()->widgetFromJsonFile("AirPlane/AirPlane.ExportJson"); //alpha1中使用
uiLayer->addWidget(myLayout);
this->addChild(uiLayer);
参考:
http://blog.csdn.net/fansongy/article/details/16950241
http://blog.csdn.net/fansongy/article/details/12757411