cocos2dx显示中文
来源:互联网 发布:知乎为什么那么火 编辑:程序博客网 时间:2024/05/21 21:38
从外部文件读取UTF-8
推荐大家使用资源文件进行配置保存,如xml将其采用的UTF-8的编码方式保存,自然会让我想到,日文、韩文等待各种国家的语言都可以正常显示了,为了你的软件国际化...尽量采用这种方式吧!到时候根据手机系统的语言,然后动态的来读取你文件中的资源...
先看下我们的xml文件:
- <dict>
- <key>chinese1</key>
- <string>美好的一天</string>
- <key>japanese</key>
- <string>良い一日を</string>
- <key>spanish</key>
- <string>Buen día</string>
- </dict>
- </plist>
然后再来看如何使用:
- //利用CCDictionary来读取xml
- CCDictionary *strings = CCDictionary::create("fonts/strings.xml");
- //中文,日语,西班牙语:objectForKey根据key,获取对应的string
- const char *chinese = ((CCString*)strings->objectForKey("chinese1"))->m_sString.c_str();
- const char *japanese = ((CCString*)strings->objectForKey("japanese"))->m_sString.c_str();
- const char *spanish = ((CCString*)strings->objectForKey("spanish"))->m_sString.c_str();
- CCLabelBMFont *label1 = CCLabelBMFont::create(spanish, "fonts/arial-unicode-26.fnt");
- addChild(label1);
- label1->setPosition(ccp(s.width/2, s.height/4*3-20));
- CCLabelBMFont *label2 = CCLabelBMFont::create(chinese, "fonts/arial-unicode-26.fnt");
- addChild(label2);
- label2->setPosition(ccp(s.width/2, s.height/4*2));
- CCLabelBMFont *label3 = CCLabelBMFont::create(japanese, "fonts/arial-unicode-26.fnt");
- addChild(label3);
- label3->setPosition(ccp(s.width/2, s.height/4*1));
运行效果:
0 0
- cocos2dx 中文显示
- cocos2dx显示中文
- cocos2dx 3.3显示中文
- cocos2dx中文显示
- cocos2dx解析xml显示中文
- cocos2dx 3.1中显示中文
- Cocos2dx 3.2的中文显示
- cocos2dx CCLabelTTF显示中文乱码
- cocos2dx 3.4 Label中文显示
- Cocos2dx杂记:如何显示中文
- cocos2dx 显示中文的三种方法
- cocos2dx 显示中文的几个方法
- cocos2dx 3.0 显示中文及乱码解决方案
- cocos2dx在windows下如何显示中文
- Android NDK Cocos2dx 3.4 Label中文显示
- cocos2dx 中文(韩文)显示方法
- Cocos2dx杂记:如何显示中文(2)
- 使用cocos2dx 在android设备上显示中文
- 使用 acl 服务器框架编写监听多个地址的服务器程序
- oracle索引优化
- 表单中"multipart/form-data",获取表单中的值
- C语言\r\n和\n区别
- 网络与服务器编程框架库 acl_3.0.12 发布
- cocos2dx显示中文
- 使用 acl_cpp 库编写多线程程序
- Linux文件I/O
- 海量数据处理:十个海量数据处理方法总结
- 网络与服务器编程框架库 acl_3.0.13 发布
- 使用 acl 编写 UDP 网络程序
- 网络与服务器编程框架库 acl_3.0.14发布
- acl --网络及服务器编程框架库 3.0.15 版本发布
- 创业孵化器公司Y Combinator,将招募更多的黑人企业家