设置地方
1.在项目解决方案上右键,添加现有项目,找到Cocostudio,GUI库以及Extensions库。
2.添加项目的附加包含目录。右键项目-》property-》configuration properties-》c/c++-》General-》Additional Include Directories,添加$(EngineRoot)cocos\editor-support,$(EngineRoot)cocos,$(EngineRoot)。
3.引用ui库。右键项目-》property-》Common Properties,Add new Reference->添加libCocosStudio,libExtensions,libGUI库。
4.rebuild整个工程。
文件中代码调用
头文件:
#include "cocos-ext.h"
#include "cocostudio/CCSGUIReader.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
USING_NS_CC_EXT;
using namespace ui;
using namespace cocostudio;
layout加载及按钮事件的添加:
Layout *pLayout = static_cast<Layout *>(GUIReader::getInstance()->widgetFromJsonFile("uiresource/weigo_mainlayer/weigo_mainlayer.ExportJson"));
this->addChild(pLayout);
Button *btnUserData = static_cast<Button *>(Helper::seekWidgetByName(pLayout, "mainlayer_userdata"));
btnUserData->addTouchEventListener(CC_CALLBACK_2(CMainScene::touchEvent, this));
btnUserData->setTag(1);
函数:
void CMainScene::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
}
cocos2d-x ui编辑器导出文件的使用