一、FontToUTF8()方法修改字体:
1、HelloWorldScene.h头文件中声明方法:
char* FontToUTF8(const char* font);
2、HelloWorldScene.cpp中书写方法:
char* HelloWorld::FontToUTF8(const char* font)
{
int len = MultiByteToWideChar(CP_ACP, 0, font, -1, NULL, 0);
wchar_t *wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_ACP, 0, font, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char *str = new char[len + 1];
memset(str, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
if (wstr)
delete[] wstr;
return str;
}
HelloWorldScene.cpp中初始化init()方法里,调用方法进行中文转换:
auto* label3 = Label::create(HelloWorld::FontToUTF8("开始游戏"), "宋体", 40);
注意:这种方法可以使运行结