3.x 显示中文

头文件:

#ifndef _ChineseWord_H_
#define _ChineseWord_H_
#include "cocos2d.h"
#include "string.h"
#include "tinyxml2/tinyxml2.h"
USING_NS_CC;
using namespace std;

static ValueVector txt_vec =  FileUtils::getInstance()->getValueVectorFromFile("data.xml");

string ChineseWord(const char* wordId);
#endif

**************************************************

cpp 文件:

#include "ChineseWord.h"
string ChineseWord(const char* wordId)
{
    auto txt_map = txt_vec.at(0).asValueMap();
    string ret = txt_map.at(wordId).asString();
    return ret;
}

***************************************************


在要用文字 的文件包含上面的头文件:


//显示中文
 
   string map1 = ChineseWord("mubiao");
  log("mubiao:%i",map1);
  auto label = Label::create(map1,"宋体",30);
  label->setPosition(visibleSize.width/2,visibleSize.height/2);
  this->addChild (label);


**********************Xml文件格式 **************************

<?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">
<array>
  <dict>
    <key>guanqia</key>
    <string>关卡</string>
      
  <key>mubiao</key>
  <string>目标</string>
    
  <key>fen</key>
  <string>分</string>
    
  <key>highestScore</key>
  <string>历史最高分</string>
    
  <key>lianji</key>
  <string>连击增加</string>
    
  <key>shengyu</key>
  <string>剩余</string>
    
  <key>ge</key>
  <string>个</string>
    
  <key>jiangli</key>
  <string>奖励</string>
</dict>
 
</array>
</plist>

*************************************************

你可能感兴趣的:(中文,include)