您的位置:首页 > 移动开发 > Cocos引擎

cocos2dx项目中使用cocostudio ui编辑器的导出文件

2014-02-26 00:25 567 查看
我的配置:xp系统,cocos2dx-2.2.0,cocostudio v1.0.0.0。



目的:点击按钮,球水平移动。

上面的截图是我的cocostudio编辑的一个简单ui界面。导出后的文件包括下图三个文件



1 在项目的资源目录下用文件夹 gmzFirst 保存这三个文件。
2 在cpp里面加入
#include"cocos-ext.h"
using namespace cocos2d::extension;
3 在 init函数里面加入
//test cocostudio ui edit

UILayer* uiLayer = UILayer::create();

this->addChild(uiLayer);
uiLayer->setTag(22);
uiLayer->addWidget(CCUIHELPER->createWidgetFromJsonFile("gmzFirst/gmzui111_1.ExportJson"));

//UIButton* butn= (UIButton*)uiLayer->getChildByTag(2);
UIButton* butn= (UIButton*)uiLayer->getWidgetByTag(2);
butn->addTouchEventListener(this,SEL_TouchEvent(&HelloWorld::startTouch));
4 添加按钮的响应函数
void HelloWorld::startTouch(CCObject* obj,TouchEventType type)
{
static int aa=0;
switch (type)
{
case TOUCH_EVENT_BEGAN:
{
CCLOG("+++begin+++");
UILayer* ui=(UILayer*)this->getChildByTag(22);
UIImageView* ball=(UIImageView*)ui->getWidgetByTag(3);

ball->setPosition(ccp(200+aa++,300));
}
break;
case TOUCH_EVENT_MOVED:
break;
case TOUCH_EVENT_ENDED:
CCLOG("+++ended+++");
break;
case TOUCH_EVENT_CANCELED:
break;
}

return ;
}
5 编译运行,可以测试了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: