Cocos porting to Android some problems-Chinese garbled problem

Source: Internet
Author: User

Android platform version and device fragmentation is very serious, so porting from the Win32 platform to the Android platform will have a lot of problems, the following is a summary of our migration from the Win32 platform to the Android platform encountered some problems.
In the Android platform Chinese garbled is not a problem, or on the Android platform should not appear in Chinese garbled. This problem is based on the fact that we have developed Android applications under Windows. By default, the Windows Chinese environment is GBK encoded, the source program file HelloWorldScene.cpp encoding by default is also GBK if there is a Chinese input in the source code, such as the following code:

[HTML] view Plaincopy

  1. void Helloworld::onclickmenu1 (object* psender)

  2. {

  3. Notedao::initdb ();

  4. Notedao::create ("2008-08-16 10:01:02", "Initialize data.") ");

  5. }

  6. void Helloworld::onclickmenu2 (object* psender)

  7. {

  8. String currenttime = myutility:: GetCurrentTime ();

  9. Log ("%s", Currenttime.c_str ());

  10. Notedao::create (CurrentTime, "Welcome to MyNote. ");

  11. }



This program compiled after the Chinese encoding is still GBK, because the Android platform uses the encoding is UTF-8, when they on the Android platform through the log functions or tags, such as control output will be garbled.
The solution is very simple, we just need to save the HelloWorldScene.cpp file as UTF-8, with the text editing tools such as Notepad and then save as UTF-8, if it is in the Visual Studio tool can choose the menu file → advanced save options, In the pop-up dialog box, select Encode as Unicode (UTF-8 with signature) and click the OK button to save.


Advanced Save Options

We only need to have Chinese characters in the file (including H and CPP files), using the Save as UTF-8 character set above, other files can not be considered. It is necessary to remember that the default standard in the character set is UTF-8 on Android and iOS platforms.


For more information, please pay attention to the first Cocos2d-x 3.2 Edition book "Cocos2d-x: C + + volume"

Book Exchange Discussion website: http://www.cocoagame.net
For more exciting video courses, please follow Cocos class: Http://v.51work6.com

Welcome to join Cocos2d-x Technical discussion group: 257760386

Welcome to Luxgen iOS Classroom public Platform


Cocos porting to Android some problems-Chinese garbled problem

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.