在Resources目录下新建一个chinese.xml,一定需要使用UTF-8格式保存文件
内容如下:
<dict>
<key>title</key>
<string>中文测试</string>
<key>1</key>
<string>人物1</string>
</dict>
在cpp代码中:
Dictionary *contents = Dictionary::createWithContentsOfFile("chinese.xml");
const char *title = ((String*)contents->objectForKey("title"))->getCString();
auto label = LabelTTF::create(title, "Arial", 24);
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
this->addChild(label, 1);
const char *p1 = ((String*)contents->objectForKey("1"))->getCString();
auto label2 = LabelTTF::create(p1, "Arial", 24);
label2->setPosition(Vec2(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height - label->getContentSize().height - 50));
this->addChild(label2, 1);
效果如如下: