Cocos 在win32 平台上显示中文(仅实现win32)

测试显示 中文或者 其它平台已经判断显示的 可以借用这偷懒的方法

在cocos-x 3.2,vs2012 环境中运行的


在所使用的.h文件中私有添加

	inline std::string WideByte2UTF8(const wstring& text)
	{
		int asciisize = ::WideCharToMultiByte(CP_UTF8,text.c_str(),text.size(),NULL,NULL);

		if (asciisize == ERROR_NO_UNICODE_TRANSLATION || asciisize == 0)
		{
			return string();
		}

		char* resultstring = new char[asciisize];

		int convresult = ::WideCharToMultiByte(CP_UTF8,resultstring,asciisize,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);

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...