打开CocoStudio UI编辑器新项目,设置画布480*320, 加入�一个标签和一个button控件
导出项目,生成所须要的资源文件, 拷贝到cocos2dprojectResources文件夹下
添�代码:
头文件:
#include "cocos2d.h"
#include "cocos-ext.h"
USING_NS_CC;
USING_NS_CC_EXT;
using namespace ui;
载入cocostudio资源创建控件
_touchgroup = TouchGroup::create();
this->addChild(_touchgroup);
_layout = static_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("root_panel.ExportJson")); //载入UI资源
_touchgroup->addWidget(_layout);//加入�画布 Layout* root = static_cast<Layout*>(_touchgroup->getWidgetByName("Panel_22")); //获取画布对象名称
Button* button = static_cast<Button*>(UIHelper::seekWidgetByName(root, "Button_1")); //获取按钮控件
button->addTouchEventListener(this, toucheventselector(HelloWorld::touchEvent)); //按钮事件 void HelloWorld::touchEvent(CCObject *pSender, TouchEventType type)
{
CCLOG("test...");
}