
将class下所有的文件全部放到Sublime Text 3中: 查找文件CTRL+P:CocoStudio.h 发现底下有个:#include "cocostudio/CCSGUIReader.h" 接着查找:CCSGUIReader.h
导入头文件调用:(注意命名空间和强制类型转换类型) 将Json文件中的控件,转换成cocos2dx里面的ui控件来 *** 作 #include "cocostudio\CocoStudio.h" #include "ui\UIbutton.h"
using namespace cocostudio;
using namespace ui; 注意类型转换的类型必须一一对应,比如TextFIEld就是TextFIEld,不能转换为TextFIEldTTF:
@H_502_154@ [cpp] view plain copy #include"HelloWorldScene.h" /*cocoStudio导出的Json文件*/ #defineJsON"Demologin.Json" #defineBTN_TAG14 #defineEDIT_TEXT_name8 /*设置命名空间*/ USING_NS_CC; usingnamespacecocostudio; namespaceui; namespacestd; Scene*HelloWorld::createScene() { autoscene=Scene::create(); autolayer=HelloWorld::create(); scene->addChild(layer); returnscene; } boolHelloWorld::init() if(!Layer::init()) returnfalse; } /*加载cocoStudio界面*/ autouiScene=GUIReader::getInstance()->WidgetFromJsonfile(JsON); addChild(uiScene); /*找到cocoStudio的控件,装换成coocs的gui控件(Helper须加载CocosGUI.h)*/ /*按钮*/ button*btn=(button*)(Helper::seekWidgetByTag(uiScene,BTN_TAG)); /*设置按钮点击事件(注意转换类型的对应)*/ btn->addtouchEventListener(this,toucheventselector(HelloWorld::touchEvent)); /*输入框(注意转换类型的对应,不是TextFIEldTTF)*/ editText=(TextFIEld*)(Helper::seekWidgetByTag(uiScene,EDIT_TEXT_name)); true; /*设置按钮点击事件*/ voIDHelloWorld::touchEvent(Ref*pSender,touchEventTypetype){ switch(type) { casetouch_EVENT_BEGAN: cclOG("Began"); break; casetouch_EVENT_MOVED: break; casetouch_EVENT_ENDED: /*输出输入框的内容*/ cclOG(editText->getString().c_str()); casetouch_EVENT_CANCELED: default: }
FROM:http://blog.csdn.net/ns2250225/article/details/41961219
给cocos中添加响应事件的例子:
#include "ui/CocosGUI.h"
//获取屏幕大小
Size visibleSize = Director::getInstance()->getVisibleSize();
auto Widget = Widget::create(); Widget->setContentSize(Size(100,100)); Widget->setposition(Vec2(visibleSize.wIDth/2,visibleSize.height/2)); Widget->settouchEnabled( true ); this ->addChild(Widget); Widget->addtouchEventListener([](Ref *pSender,Widget::touchEventType type){ switch (type) { case Widget::touchEventType::BEGAN: cclOG( "BEGAN" ); break ; Widget::touchEventType::MOVED: "MOVED" ); ; Widget::touchEventType::ENDED: "ENDED" ); ; @H_404_579@ Widget::touchEventType::CANCELED: "CANCELED" ); ; default : ; } }); from:http://www.cocoachina.com/bbs/read.PHP?tID-289092.HTML
总结以上是内存溢出为你收集整理的【cocosStudio】查看官方示例--调用cocoStudio控件全部内容,希望文章能够帮你解决【cocosStudio】查看官方示例--调用cocoStudio控件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)