測試顯示 中文或者 其它平臺已經判斷顯示的 可以借用這偷懶的方法
在cocos-x 3.2 ,vs2012 環境中運行的
在所使用的.h文件中私有添加
inline std::string WideByte2UTF8(const wstring& text)
{
int asciisize = ::WideCharToMultiByte(CP_UTF8, 0, text.c_str(), text.size(), NULL, 0, NULL, NULL);
if (asciisize == ERROR_NO_UNICODE_TRANSLATION || asciisize == 0)
{
return string();
}
char* resultstring = new char[asciisize];
int convresult = ::WideCharToMultiByte(CP_UTF8, 0, text.c_str(), text.size(), resultstring, asciisize, NULL, NULL);
if (convresult != asciisize)
{
return string();
}
std::string buffer(resultstring, convresult);
delete[] resultstring;
return buffer;
}
在cpp中調用
std::string str = "";
str = WideByte2UTF8(L"你好世界");
Label* label = Label::createWithSystemFont(str.c_str(), "Arial", 20);
label->setColor(Color3B::RED);
label->setPosition(200, 200);
this->addChild(label);