cocos2dx中使用中文
来源:互联网 发布:数控加工中心编程100例 编辑:程序博客网 时间:2024/06/07 06:44
方法一 使用 xml
在vs中创建xml
<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict><key>startGame</key><string>开始游戏</string><key>japanese</key><string>地方</string></dict></plist>
代码中使用
Dictionary* dic = Dictionary::createWithContentsOfFile("chineseString.xml");String* strchinese = (String*)dic->objectForKey("startGame");LabelBMFont* bmFont = LabelBMFont::create(strchinese->getCString(),"font_1.fnt");addChild(bmFont,0,1000);bmFont->setPosition(Point(200,500));bmFont->setWidth(20);
方法二 使用类库
首先创建一类库 名为G2UTool
#ifndef __TOOLS_H__ #define __TOOLS_H__ #include <string> #include "iconv/iconv.h"using namespace std;class G2UTool{public:static int GBKToUTF8(std::string &gbkStr); };#endif
#include "G2UTool.h"int G2UTool::GBKToUTF8(std::string &gbkStr) { iconv_t iconvH; iconvH= iconv_open("utf-8","gb2312"); if(iconvH == 0){ return -1; } const char* strChar= gbkStr.c_str(); const char** pin= &strChar; size_t strLength= gbkStr.length(); char* outbuf= (char*)malloc(strLength*4); char* pBuff= outbuf; memset(outbuf,0,strLength*4); size_t outLength = strLength*4; if(-1 == iconv(iconvH,pin,&strLength,&outbuf,&outLength)){ iconv_close(iconvH); return -1; } gbkStr=pBuff; iconv_close(iconvH); return 0; }
然后再cocos2dx中调用
std::string str2 = "开始游戏";G2UTool::GBKToUTF8(str2);LabelBMFont* bmFont = LabelBMFont::create(str2.c_str(),"font_1.fnt");addChild(bmFont,0,1000);bmFont->setPosition(Point(200,500));bmFont->setWidth(20);
0 0
- cocos2dx中使用中文
- [cocos2dx]在cocos2dx中使用iconv库解决中文乱码
- 在cocos2dx 中如何使用中文
- cocos2dx 3.1中显示中文
- cocos2dx中使用多线程
- Cocos2dx中使用多线程
- cocos2dx中使用GLProgramState
- cocos2dx 中使用 opencv
- cocos2d-x中文显示问题解决方法(使用cocos2dx中自带的iconv实现)
- cocos2d-x中文显示问题解决方法(使用cocos2dx中自带的iconv实现)
- Cocos2dx 自定义字体的使用(中文)
- cocos2dx中如何使用HttpClient ?
- quick-cocos2dx中使用pomelo
- cocos2dx中使用触摸事件
- quick-cocos2dx中使用pomelo
- cocos2dx 中 ProgressTimer的使用
- Cocos2dx中ValueMap的使用
- cocos2dx中使用多线程(转)
- linux centos的不足
- php5.4中htmlspecialchars中文为空的解决办法
- 从网上找的DBMS_STATS.SET_DATABASE_PREFS资料
- Tcl/TK -- Http data
- 2014-1-10 17:18:15
- cocos2dx中使用中文
- androguard中androdd文件名过长bug
- 怎样用互联网思维意淫一家豆浆店
- impala
- R foundmental
- 如何在iOS中使用Block──How to use Blocks with iOS
- C++面向对象作业我之解答
- 好吧,CSS3 3D transform变换,不过如此!
- 互斥锁和条件变量