位置: 编程技术 - 正文

cocos2dx 3.4 Label中文显示

编辑:rootadmin

推荐整理分享cocos2dx 3.4 Label中文显示,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

第一种方式:

Label* a = Label::createWithSystemFont("中国", "宋体", );a->setPosition(Point(, ));addChild(a);

这种方式也可以显示中文,不过显示中文的个数必须是双数,单数会产生莫名其妙的错误,不建议使用

第二种方式 这种方式只能使用已经设置好的中文

是采用xml的方式显示中文

cocos2dx 3.4  Label中文显示

XML内容:

__Dictionary* string = __Dictionary::createWithContentsOfFile("string.xml");__String* a = (__String*)string->objectForKey("yes1");const char* b= a->getCString();Label* label = Label::createWithSystemFont(b, "宋体", );label->setPosition(Point(, ));addChild(label);

第三种方式

这个是我自己在网上搜的一些资料整理而成的,我给封装成了一个类,用的时候添加该类,直接用就可以了

#ifndef _CHINESE_DISPLAY_H_#define _CHINESE_DISPLAY_H_#include <iostream>#include "stringapiset.h"#include "winerror.h"using namespace std;class chineseDisplay{public:static string a(char *b){wstring cc = str2wstr(b);return WideByte2UTF8(cc);}private:static wstring str2wstr(const string &str){setlocale(LC_ALL, "chs");const char* _Source = str.c_str();size_t _Dsize = str.size() &#; 1;wchar_t *_Dest = new wchar_t[_Dsize];wmemset(_Dest, 0, _Dsize);mbstowcs(_Dest,_Source,_Dsize);wstring result = _Dest;delete []_Dest;setlocale(LC_ALL, "C");return result;}static 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;}};#endif

cocos2dx3.4 Menu 菜单项的创建方式有6种,分别为以一个Node的节点创建staticMenuItemLabel*create(Node*label);MenuItemLabel以一个地图集创建,参数包括字符串,地图文件,项目的

cocos2d-x 3.4 windows 环境配置 首先从官网下载cocos2d-x并解压

从svn上下载的cocos2d-x工程报错 LOCAL_SRC_FILES points to a missing file *** Android NDK: Aborting . Stop. 从svn下载同事建立的cocos2d-x工程,导入Eclipse后编译报错(同事的不报错):***AndroidNDK:Aborting.Stop.AndroidNDK:ERROR:jni/../../cocos2d/external/freetype2/prebuilt/android/Andro

本文链接地址:https://www.jiuchutong.com/biancheng/368861.html 转载请保留说明!

上一篇:cocos2dx笔记--hellolua 示例(cocos2dx官方教程)

下一篇:cocos2dx3.4 Menu

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络