码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-x加载cocostudio

时间:2014-05-07 01:58:01      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:android   style   ext   color   get   文件   

1、cocos2d-x加载cocostudio一定要用对应的版本,不然很是麻烦

  1)、先说说coco2d-x3.0和cocostudio1.3.0.1UI

  2)、先用cocostudio导出工程,这个没什么太多可说,美术的事情,不过要注意像button那样的,要选中交互。

  3)、将导出的资源放入cocos2d-x资源目录中

  4)、由于cocos2d-x3.0工作目录是放在其它地方,所以要引用一些库 libCocoStuido、libGUI和libExtension三个库

  5)、他们存在路径不同分别在 cocos/editor-support/cocostudio/proj.win32/libCocoStuido 、cocos2d\cocos2d-x-3.0\cocos\ui\proj.win32

         、 cocos2d\cocos2d-x-3.0\extensions\proj.win32

  6)、添加库方法:在“解决方案资源管理器”中找到整个解决方案,右击,选择“添加”->“现有项目”。在弹出的对话框中找到“项目目录/cocos2d/cocos/editor-

        support/cocostudio/proj.win32/libCocoStuido”点击确定,即可加入到解决方案中

  7)、找到我们的目标项目“Test”右击,选择“引用...”。在弹出的属性页中点选下面的“添加新引用”。在弹出的子级对话框中选择我们需要的库,点击确

       定,即可添加项目对库的引用。

  8)、添加包含目录: 右击项目->属性->配置属性->c/c++->常规->加入包含目录“$(EngineRoot)cocos\editor-support”和“$(EngineRoot)cocos”。

  9)、引入头文件 #include "cocostudio/CocoStudio.h"

  10)、代码:

        auto uiLayer = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("DemoLogin/DemoLogin.json");         addChild(uiLayer);

  11)、设置button按钮监听 引用UIWidget添加命名空间uUSING_NS_CC; sing namespace ui;

  12)、代码

    uiLayer->getChildByName("login_Button")->addTouchEventListener(this, toucheventselector(HelloWorld::touchCallBack));

    void HelloWorld::touchCallBack(Object* obj,TouchEventType type)

2、再说说cocos2d-x3.0加载cocostudio1.3.0.1的场景

  1)、头文件和链接库如上所示,如果已经加载那就不用再加载了

  2)、用cocostudio生成场景文件,拷贝到cocos2d-x资源目录下,注意不要把这些文件自己建立的次目录下

  3)、加载整个文件到场景中使用 cocostudio::SceneReader

        auto node = cocostudio::SceneReader::getInstance()->createNodeWithSceneFile("publish/FightScene.json");         addChild(node);

  4)、播放动画

          auto child = node->getChildByTag(10005);            auto pLoadRender = (cocostudio::ComRender*)(child->getComponent("CCArmature"));            auto pArmature = (cocostudio::CCArmature*)(pLoadRender->getNode());           pArmature->getAnimation()->playByIndex(1);

   5)、获取场景文件中的精灵

        auto pLoadRender1 = (cocostudio::ComRender*)(node->getChildByTag(10011)->getComponent("CCSprite"));         Sprite *ssss = (Sprite*)(pLoadRender1->getNode());

  6)、场景中的节点,可以通过getchind...方式一层层获取。 node->getChildByTag(10007)->getChildByTag(10010)->getComponent("CCSprite")

3、再说一下到Android平台移植问题

   1、android 还需在jni/android.mk下重添加引用库cocostudio

   2、添加LOCAL_WHOLE_STATIC_LIBRARIES += cocostudio_static和$(call import-module,editor-support/cocostudio)

 以下是老版本

1、首先用cocostudio导出工程(在此说明一下,cocostudio1.2.0.1导出的UI能在cocos2d-x2.2中使用,但是不能在cocos2d-x2.2.3中使用,cocostudio1.2.0.1导出的骨骼动画能在cocos2d-x2.2.3中使用但是不能在cocos2d-x2.2中使用,你说操蛋不,所以使用cocostudio1.2.0.1建议用cocos2d-x2.2.2)

2、UILayer与UIWidget :

     UILayer 继承cocos2d-x的CCLayer,UILayer可以通过addWidget添加UIWidget。下面该熟悉了吧

3、 UIWidget* view = CCUIHELPER->createWidgetFromJsonFile("qq/NewProject_1.json"); UILayer *ui = UILayer::create(); ui->addWidget(view);

UITextButton *button = dynamic_cast<UITextButton*>(ui->getWidgetByName("Button_28"));  //根据名称获取button

button->addTouchEventListener(this,SEL_TouchEvent(&HelloWorld::menuCallback));

//下面是cocos2d-x2.2的写法 //button->addReleaseEvent(this,coco_releaseselector(LoginScene::tryGame));  //添加时间回调监听

      this->addChild(ui);

4、void HelloWorld::menuCallback(CCObject* pSender,TouchEventType type){}

cocos2d-x加载cocostudio,布布扣,bubuko.com

cocos2d-x加载cocostudio

标签:android   style   ext   color   get   文件   

原文地址:http://www.cnblogs.com/xhg986/p/3712159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!