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 = “新局”;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
GBKToUTF8(menuItemStr,“gb2312”,“utf-8”);//调用字符转换函数
#endif
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.
regards,
googleman
assertionfail.jpg (55.2 KB)
assertionfail.jpg (55.2 KB)