text.xml文件
- 新建一個txt文件
- 按下面的格式輸入鍵值對
- 另存爲UTF-8格式的.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<key>play</key>
<string>開始遊戲</string>
<key>title</key>
<string>標題</string>
</dict>
step1讀取xml文件
auto dic = Dictionary::createWithContentsOfFile("fonts/text.xml");
step2通過xml讀取中文到字符串
auto str = (String*)(dic->objectForKey("title"));
step3用中文字符串創建中文標籤
auto title = Label::create();
title->setString(str->getCString());
title->setSystemFontSize(60);
title->setColor(Color3B(174.0f, 111.0f, 23.0f));
title->setPosition(Vec2(visibleSize.width / 2,
visibleSize.height - title->getContentSize().height));
this->addChild(title);
中文菜單
用中文標籤創建
auto start_menu = MenuItemLabel::create(title,CC_CALLBACK_1(StartGame::startPlay,this));
auto menu = Menu::create(start_menu, NULL);
menu->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 4));
this->addChild(menu);
用中文字符串直接創建
MenuItemFont::setFontName("Arial");
MenuItemFont::setFontSize(40);
MenuItemFont *item1 = MenuItemFont::create(str->getCstring(),
CC_CALLBACK_1(StartGame::startPlay, this));