cocos2d-x解决中文乱码问题(详细)!(跨平台)
2014-03-15 20:36
501 查看
参考:http://www.2cto.com/kf/201305/215140.html
出现乱码原因:.cpp文件默认编码GBK
解决办法将字符串单独放到一个文件中:我放在了资源文件夹下strings.xml文件中。
内容如下:
<dict>
<key>Hello</key>
<string>你好!</string>
<key>Info</key>
<string>我是hahaya。</string>
</dict>
注意:保存文件的时候用UTF-8编码,
然后建立一个工具类:
Str_covertCode.h :
使用如下:
CCMenuItemFont::create(Str_convertCode::Str_convertCodeByKey("Hello"));
只需要一个参数,就是上面strings.xml文件中的KEY 字段。
第一次写博客加上网速在10kb左右光图片就传了好几次才成功,唔!
出现乱码原因:.cpp文件默认编码GBK
解决办法将字符串单独放到一个文件中:我放在了资源文件夹下strings.xml文件中。
内容如下:
<dict>
<key>Hello</key>
<string>你好!</string>
<key>Info</key>
<string>我是hahaya。</string>
</dict>
注意:保存文件的时候用UTF-8编码,
然后建立一个工具类:
Str_covertCode.h :
#include "cocos2d.h" USING_NS_CC; class Str_convertCode{ public: static const char* Str_convertCodeByKey(char* str){ CCDictionary *itemsString=CCDictionary::createWithContentsOfFile("strings.xml"); const char* itemString =((CCString*)itemsString->objectForKey(str))->m_sString.c_str(); return itemString; } }; /** 在cocos2d-x中使用中文 **/ //利用CCDictionary来读取xml //CCDictionary *strings = CCDictionary::createWithContentsOfFile("strings.xml"); // strings.xml 文件 在资源目录下 //读取Hello键中的值 objectForKey根据key,获取对应的string //const char *hello = ((CCString*)strings->objectForKey("Hello"))->m_sString.c_str();
使用如下:
CCMenuItemFont::create(Str_convertCode::Str_convertCodeByKey("Hello"));
只需要一个参数,就是上面strings.xml文件中的KEY 字段。
第一次写博客加上网速在10kb左右光图片就传了好几次才成功,唔!
相关文章推荐
- cocos2d-x封装一个转码的工具解决中文乱码可以直接拖过去用通用跨平台
- Cocos2d-x 3.1.1 学习日志4--cocos2d-x解决中文乱码问题的几种办法
- cocos2d-x解决中文乱码问题
- cocos2d-x解决中文乱码问题的几种办法
- cocos2d-x中文乱码问题解决
- 解决cocos2d-x 中文乱码的问题
- [Cocos2D-X]使用iconv解决VS上中文显示乱码的问题+android导入第三方库iconv
- Tomcat中文乱码问题的原理和解决方法(全面、详细)
- 通俗易懂地解决中文乱码问题(1) --- 跨平台乱码
- cocos2d-x解决中文乱码问题的几种办法
- cocos2d-x中文乱码问题解决
- cocos2d-x 3.2 在window平台vs2012下解决中文乱码问题
- Cocos2d-x 3.1.1 学习日志4--cocos2d-x解决中文乱码问题的几种办法
- cocos2d-x 3.x 中文乱码问题解决
- php -- 解决php连接sqlserver2005中文乱码问题(附详细解决方法)
- cocos2d-x 3.2 在window平台vs2012下解决中文乱码问题
- Cocos2d-x 学习随记二 Boost::Locale解决中文乱码问题
- 用加载字符串配置文件的方式解决cocos2D-x项目中文乱码问题
- cocos2d-x解决中文乱码问题的几种办法
- 关于Cocos2d-x中文乱码问题的解决