Problems with Cocos porting to Android-Chinese Garbled text, cocosandroid

Source: Internet
Author: User

Problems with Cocos porting to Android-Chinese Garbled text, cocosandroid
The version and device fragmentation of the Android platform are very serious. Therefore, porting from the Win32 platform to the Android platform has many problems. The following are some problems we have encountered from migrating the Win32 platform to the Android platform.
Chinese Garbled text on the Android platform is not a problem, or Chinese Garbled text should not appear on the Android platform. The root cause of this problem is that we develop Android applications in Windows. By default, the Windows Chinese environment uses GBK encoding. The HelloWorldScene. cpp encoding in the source program file is also GBK by default. If there is any Chinese input in the source code, for example, the following code:

Void HelloWorld: OnClickMenu1 (Object * pSender) {NoteDAO: initDB (); NoteDAO: create ("10:01:02", "initialize data. ");} Void HelloWorld: OnClickMenu2 (Object * pSender) {string currentTime = MyUtility: getCurrentTime (); log (" % s ", currentTime. c_str (); NoteDAO: create (currentTime, "Welcome to MyNote. ");}


In this way, the Chinese encoding after the program is compiled is GBK, because the Android platform uses the encoding is UTF-8, when they are in the Android platform through the log function or tag control output will be garbled.
The solution is simple. We only need to put HelloWorldScene. cpp file can be saved as a UTF-8, with notepad and other text editing tools and then save it as a UTF-8, if it is in Visual Studio Tools can choose menu file → advanced save options, in the dialog box that appears, select encode as Unicode (UTF-8 with signature) and click OK to save.

Advanced save options

We only need to have a Chinese character files (including h and cpp files), using the above save as UTF-8 character set can be, other files can not be considered. It should be noted that the UTF-8 on Android and iOS platforms is the default standard in character sets.


More content please pay attention to the first domestic Cocos2d-x 3.2 version of the book "Cocos2d-x practice: C ++ volume" book exchange discussion site: http://www.cOcoagame.net
For more exciting video courses, please follow the Cocos course in Zhijie class: http: // v.51wOrk6.com
Welcome to the Cocos2d-x Technology Discussion Group: 257760386 welcome to the knowledge of the iOS classroom public platform

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.