How to render Chinese characters on Android platform

How to render Chinese characters on Android platform
0.0 0


Hello cocos2d-x comrades,

I’m a guy from WeiFang China and also a beginner in cocos2d-x. Now one of my puzzles is around Chinese characters rendering on android. In win32 case, I’ve got the following method which I think is ENOUGH:

@ std::string menuItemStr = “新局”;
CCLabelTTF* lblNew = CCLabelTTF::create(menuItemStr.c_str(),“Marker Felt”, 24);

However, when I shift above code to android, Chinese characters cannot be displayed, with only some messed stuff. I surfed the web, but found no satisfying answers. So, I come again here for help.

My idea is try to find a good way that works both on Win32 case and on android platform, one of the reasons being that win32 debugging is rather faster than android, as well as more convinient. Hence, I tried to use the below coding under WIN32:

CCLabelBMFont* pLabel = CCLabelBMFont::create("中国", "fonts/bitmapFontChinese.fnt");

And also, I put the two files, bitmapFontChinese.fnt and bitmapFontChinese.png, under the folder fonts which lies under the folder Resources. However, when I run the above code under win32 case, “Assertion failed!” is still thrown out, as shown in the attached .jpg file. When I pressed “Retry” to track the debugging, the code stopped at the following position:

unsigned int key = c;
HASH_FIND_INT(m_pConfiguration->m_pFontDefDictionary, &key, element);
CCAssert(element, “FontDefinition could not be found!”);

NOTE: the above code is in function void CCLabelBMFont::createFontChars()
. So, does it means I put the above two files at the wrong sites? Am I wrong in some other related cases?

Expect your quick help. And thanks in advance.



assertionfail.jpg (55.2 KB)

assertionfail.jpg (55.2 KB)



I’ve just run the demo testcpp on Win32 and everything run OK — the LabelTest can render perfect

Chinese characters with the following code:

CCLabelTTF *pLable = CCLabelTTF::create(“中国”, “Marker Felt”, 30);

And also OK:

CCSize size = CCDirector::sharedDirector()>getWinSize;
CCLabelBMFont* pLable = CCLabelBMFont::create;
>setPosition(ccp(size.width / 2, size.height /2));


So, where am I wrong as described in my first submission? Long to give some hint.




Now, I can make success in the following forms of code:

CCDictionary strings = CCDictionary::createWithContentsOfFile;
const char
chinese = ((CCString**)strings~~>objectForKey)>m_sString.c_str;
const charjapanese = ((CCString)strings
const char**spanish = ((CCString*)strings

CCSize s = CCDirector::sharedDirector()>getWinSize;
CCLabelBMFont **label1 = CCLabelBMFont::create;
CCLabelBMFont *label2 = CCLabelBMFont::create;
CCLabelBMFont**label3 = CCLabelBMFont::create;
label3~~>setPosition(ccp(s.width/2, s.height/4*1));


Now, my puzzle is still around the cases covered in the first submission. Could anyone lend me some help?