zoukankan      html  css  js  c++  java
  • cocos2d(3.0)一些基础的东西

    1.创建项目后环境配置:

    附加文件夹:加入

    $(EngineRoot)

    $(EngineRoot)cocos

    $(EngineRoot)cocoseditor-support

    $(EngineRoot)buildDebug.win32

    ..proj.win32

    通用属性加入

    (先从 cocos2d-x-3.0rc0 中 extensions   cocoseditor-support   cocosui 加入进去)

    libcocosstudio

    libExtensions

    libGUI

    链接器 附加依赖项:

    libGUI.lib
    libCocosStudio.lib
    libExtensions.lib

    头文件的加入:

    这些都放在头文件中

    #include "cocos2d.h"
    #include "uiCocosGUI.h"
    #include "cocos-ext.h"
    #include "uiUIButton.h"
    #include "cocostudioCocoStudio.h"
    #include "editor-supportcocostudioCCSGUIReader.h"
    #include <iostream>

    using namespace std;
    using namespace cocos2d;
    using namespace cocostudio;
    using namespace ui;

    在init中就能够将外部建好的场景倒入进来

    auto m_layout = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("login_ui\NewUI_1.ExportJson");
     this->addChild(m_layout);

    场景中的button和代码链接UI_BUTTON_LOGIN是在外部场景中的tag值

     Button* startBtn = dynamic_cast<Button*>(m_layout->getChildByTag(UI_BUTTON_LOGIN)); 
     startBtn->addTouchEventListener(this,toucheventselector(HelloWorld::touchButton));

    场景中的中文字符的显示:

    wstring HelloWorld::charToWstring(const char* c) 

     wstring ws; 
     int len = MultiByteToWideChar(CP_ACP,0,c,strlen(c),NULL,0); 
     wchar_t* m_wchar=new wchar_t[len+1]; 
     MultiByteToWideChar(CP_ACP,0,c,strlen(c),m_wchar,len); 
     m_wchar[len]='';

     ws.append(m_wchar); 
     return ws; 
    }

    inline std::string WideByte2UTF8(const wstring& text)

    {

     int asciisize = ::WideCharToMultiByte(CP_UTF8, 0, text.c_str(), text.size(), NULL, 0, NULL, NULL);

     if (asciisize == ERROR_NO_UNICODE_TRANSLATION ||

      asciisize == 0) 

     { 

      return string();

     }

     char* resultstring = new char[asciisize];

     int convresult = ::WideCharToMultiByte(CP_UTF8, 0, text.c_str(), text.size(), resultstring, asciisize, NULL, NULL);

     if (convresult != asciisize)

     { 

      return string();

     } 

     std::string buffer(resultstring, convresult);

     delete[] resultstring;

     return buffer;

    }

    button切换场景

    void HelloWorld::touchButton(Ref* obj,TouchEventType eventype)

    {

    Scene* pScene = ui_login_tag::createScene();
     Director::sharedDirector()->replaceScene(pScene);

    }

    加入动画:

    ArmatureDataManager::getInstance()->addArmatureFileInfo("MyAnimation.ExportJson");
     Armature* armature = Armature::create("MyAnimation");
     armature->setTag(AM_MYANIMATION);

     armature->setPosition(Point(visibleSize.width/2,visibleSize.height/2));
     
     this->addChild(armature);

    button播放动画

    auto armature = (Armature*)getChildByTag(AM_MYANIMATION);
     switch (type)
     {
     case TouchEventType::TOUCH_EVENT_ENDED:
      if(tag == UI_BUTTON_BUTTON_PLAY1)
      {
       armature->getAnimation()->play("hit");
      }else if(tag == UI_BUTTON_BUTTON_PLAY2)
      {
       armature->getAnimation()->play("fall");
      }
      break;
     default:
      break;
     }

  • 相关阅读:
    excel经典图表
    excel数据透视表
    excel常用快捷键和技巧
    excel常用公式--时间序列类
    excel常用公式--计算统计类
    excel常用公式--逻辑运算类
    excel常用公式--关联匹配类
    FileWriter字符输出流和FileReader字符输出流
    FileOutputStream字节输出流和FileInputStream输入流(切记:out是输出到本地中,in是输入到程序中)这里介绍大文件和小文件的读取方式
    DataInputStream(二进制输入流)和DataOutputStream二进制输出流(注意:in是从本地文件输入到程序中,out是从程序输出到本地种)
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/3819854.html
Copyright © 2011-2022 走看看