CCConfiguration::sharedConfiguration()->loadConfigFile cocos2d-x 中文乱码问题及国际化解决方案
2013-08-08 16:32
295 查看
from:://http://www.cnblogs.com/sunguangran/archive/2013/07/29/3222660.html
将显示文本单独保存为文本文件
在cocos2d-x的示例项目中有关于配置文件读取的示例项目,有兴趣的童鞋可以自己去找下,这里将示例内容简化进行简要介绍。
首先,相关配置文件必须放在项目Resource目录下,可自己设置二级目录,方便管理,
strings.plist内容如下:
之后我们在自己的cocos2d-x项目导演类实例生成之前需要调用下面代码进行初始化操作:
一般我们在 AppDelegate::applicationDidFinishLaunching() 起始执行该部操作。之后就可以在程序中使用配置文件中的内容了:
这样,就可以将 strings.plist 中的hello项读取出现显示,
将显示文本单独保存为文本文件
在cocos2d-x的示例项目中有关于配置文件读取的示例项目,有兴趣的童鞋可以自己去找下,这里将示例内容简化进行简要介绍。
首先,相关配置文件必须放在项目Resource目录下,可自己设置二级目录,方便管理,
strings.plist内容如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>data</key> <dict> <key>hello</key> <string>完美世界,完美生活</string> <key>cocos2d.x.display_fps</key> <true/> <key>cocos2d.x.gl.projection</key> <string>3d</string> <key>cocos2d.x.texture.pixel_format_for_png</key> <string>rgba8888</string> <key>cocos2d.x.texture.pvrv2_has_alpha_premultiplied</key> <false/> </dict> <key>metadata</key> <dict> <key>format</key> <integer>1</integer> </dict> </dict> </plist>
之后我们在自己的cocos2d-x项目导演类实例生成之前需要调用下面代码进行初始化操作:
CCConfiguration::sharedConfiguration()->loadConfigFile("config/strings.plist");
一般我们在 AppDelegate::applicationDidFinishLaunching() 起始执行该部操作。之后就可以在程序中使用配置文件中的内容了:
CCConfiguration *conf = CCConfiguration::sharedConfiguration(); const char *helloStr = conf->getCString("hello", "unknown"); CCLabelTTF* pLabel = CCLabelTTF::create(helloStr, "Arial", 24); pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); this->addChild(pLabel, 1);
这样,就可以将 strings.plist 中的hello项读取出现显示,
相关文章推荐
- Spring mvc 国际化支持已经UTF-8中文乱码问题的解决方案
- JSP+ MySQL中文乱码问题post提交乱码解决方案
- source insight中文注释乱码问题的解决方案
- SecureCRT中文乱码问题解决方案
- mysql 中文乱码问题的解决方案
- <a href>传参的中文乱码问题
- node.js jsdom gb系列网页中文乱码问题解决方案
- JSP中文乱码问题终极解决方案
- Mysql中文乱码问题完美解决方案
- 中文乱码问题原理及解决方案
- [HttpClient]HTTPClient PostMethod 中文乱码问题解决方案(2种)
- Mysql中文乱码问题完美解决方案
- Java 关于中文乱码问题的解决方案与经验
- Mysql中文乱码问题完美解决方案(包括建库、导入数据、网页)
- JSP中文乱码问题终极解决方案
- ervlet 中文乱码问题及解决方案剖析
- Java 关于中文乱码问题的解决方案与原理
- SSH框架项目+jsp页面+MySQL数据库,数据中文乱码问题解决方案合集
- 云服务器Ubuntu系统下中文乱码问题解决方案
- struts解决中文乱码和国际化问题