cocos2d(3.0)一些基础的东西
2014-04-23 17:22
218 查看
1.创建项目后环境配置:
附加目录:添加
$(EngineRoot)
$(EngineRoot)cocos
$(EngineRoot)cocos\editor-support
$(EngineRoot)build\Debug.win32
..\proj.win32
通用属性添加
(先从 cocos2d-x-3.0rc0 中 extensions cocos\editor-support cocos\ui 添加进去)
libcocosstudio
libExtensions
libGUI
链接器 附加依赖项:
libGUI.lib
libCocosStudio.lib
libExtensions.lib
头文件的添加:
这些都放在头文件里
#include "cocos2d.h"
#include "ui\CocosGUI.h"
#include "cocos-ext.h"
#include "ui\UIButton.h"
#include "cocostudio\CocoStudio.h"
#include "editor-support\cocostudio\CCSGUIReader.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);
场景中的按钮和代码链接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]='\0';
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;
}
按钮切换场景
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);
按钮播放动画
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;
}
附加目录:添加
$(EngineRoot)
$(EngineRoot)cocos
$(EngineRoot)cocos\editor-support
$(EngineRoot)build\Debug.win32
..\proj.win32
通用属性添加
(先从 cocos2d-x-3.0rc0 中 extensions cocos\editor-support cocos\ui 添加进去)
libcocosstudio
libExtensions
libGUI
链接器 附加依赖项:
libGUI.lib
libCocosStudio.lib
libExtensions.lib
头文件的添加:
这些都放在头文件里
#include "cocos2d.h"
#include "ui\CocosGUI.h"
#include "cocos-ext.h"
#include "ui\UIButton.h"
#include "cocostudio\CocoStudio.h"
#include "editor-support\cocostudio\CCSGUIReader.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);
场景中的按钮和代码链接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]='\0';
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;
}
按钮切换场景
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);
按钮播放动画
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;
}
相关文章推荐
- cocos2d(3.0)一些基础的东西
- 一些基础的东西总结一下
- Cocos2d-x 3.0 Android修改APK名、更改图标、修改屏幕方向、修改版本号,一些需要注意的问题
- java一些基础的东西
- 关于升级swif3.0,Xcode8和iOS 10的一些东西
- oracle一些杂乱的基础东西!
- bfc和ifc以及前端基础的一些东西(未整理)
- 关于升级swif3.0的一些东西(续)
- 浅谈HOOK API 都是一些很老很基础的东西
- css的一些基础的东西
- 一些基础但常用的东西
- JS基础的一些东西
- css的一些基础的东西
- [转帖] 浅谈HOOK API 都是一些很老很基础的东西 (当然,大牛们可以无视直接PASS!)
- 【Cocos2d-x 3.0 基础系列一】 各类回调函数写法汇总
- cocos2d-x 2.0升级为3.0一些常见变化纪录
- 计算机的一些基础东西
- css的一些基础的东西
- 新建一个cocos2d-x 3.0项目 等基础操作
- 选择cocos2d-js的原因,摘录了官网的一些东西