zoukankan      html  css  js  c++  java
  • CCConfiguration::sharedConfiguration()->loadConfigFile cocos2d-x 中文乱码问题及国际化解决方案

    from:://http://www.cnblogs.com/sunguangran/archive/2013/07/29/3222660.html

    将显示文本单独保存为文本文件

        在cocos2d-x的示例项目中有关于配置文件读取的示例项目,有兴趣的童鞋可以自己去找下,这里将示例内容简化进行简要介绍。

        首先,相关配置文件必须放在项目Resource目录下,可自己设置二级目录,方便管理,

    image

        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项读取出现显示,

    image

     
     
    分类: cocos2d-x
  • 相关阅读:
    第二次结对作业(陆桂莺+崔亚明)
    第一次结对作业
    第二次作业:代码互改
    markdown详细
    第一次个人编程作业:我的分数我做主
    手动下载transformers的模型
    torch设置GPU
    Python import的搜索路径和不可以import的解决方法 (On Linux)
    Python中windows路径的3种写法
    一台计算机安装多个版本的torch和CUDA的教程
  • 原文地址:https://www.cnblogs.com/wanqieddy/p/3246117.html
Copyright © 2011-2022 走看看