A collection of issues that must be addressed when porting Win32 games to the Android platform

Source: Internet
Author: User
Tags addchild

There are many problems in this area, and it is difficult to find the answers on the Internet. I'm here to put a game of my own from WIN32 to the Android transplant process must face and to solve problems, listed (some have been answered, some have not resolved).

1. How to display your own game program icon

This use of traditional Android platform ideas can be implemented, that is, modify the project Proj.android\res path under DRAWABLE-HDPI, drawable-ldpi, drawable-mdpi, The Icon.png file under drawable-xhdpi.

Note: In one experiment I only modified the files under DRAWABLE-HDPI and drawable-mdpi without modifying the icon under DRAWABLE-LDPI, and the result was in the final real machine (Samsung I9100) on the display is still the system default icon under DRAWABLE-LDPI. As a result, you can only accomplish this by modifying the icon in the folder above (which can be empty) to a consistent image file.

2, Chinese font display

This problem is more complicated because there are many situations. Let's discuss each of them individually. The primary reference resource is the labeltest part of the testcpp example that accompanies the engine.
It is worth noting that there are a few examples of the Chinese character display, because we are most concerned in this article, the first is to display the normal Chinese characters under WIN32, and then on the Android platform can also display the Chinese characters normally,
So, these examples need to be studied carefully.

Example 1:bmfontunicode class.

The complete code is as follows:

Ccdictionary *strings = Ccdictionary::createwithcontentsoffile ("Fonts/strings.xml");
const char *chinese = ((ccstring*) Strings->objectforkey ("Chinese1"))->m_sstring.c_str ();
const char *japanese = ((ccstring*) strings->objectforkey ("Japanese"))->m_sstring.c_str ();
const char *spanish = ((ccstring*) strings->objectforkey ("Spanish"))->m_sstring.c_str ();


Ccsize s = ccdirector::shareddirector ()->getwinsize ();

Cclabelbmfont *label1 = cclabelbmfont::create (Spanish, "Fonts/arial-unicode-26.fnt", $, kcctextalignmentleft);
AddChild (Label1);
Label1->setposition (CCP (S.WIDTH/2, s.height/4*3));

Cclabelbmfont *label2 = cclabelbmfont::create (Chinese, "fonts/arial-unicode-26.fnt");
AddChild (Label2);
Label2->setposition (CCP (S.WIDTH/2, s.height/4*2));

Cclabelbmfont *label3 = cclabelbmfont::create (Japanese, "fonts/arial-unicode-26.fnt");
AddChild (LABEL3);
Label3->setposition (CCP (S.WIDTH/2, s.height/4*1));



The above code can display Chinese characters correctly under WIN32 and on the Android platform. The following is a screenshot of the results from the Android platform on the real machine.

650) this.width=650; "src=" http://blog.itpub.net/attachments/2012/11/14466241_201211052147331.jpg "border=" 0 "alt= "14466241_201211052147331.jpg"/>

Recently, I spent a lot of time on the Internet, and finally basically decided to use Cclabelbmfont display text is a very good choice (some articles said Cclabelttf there is an efficiency problem, first not used).

So, just use the string in the first argument of the Create method above, for example "China", OK? no!!!!!!!!!!!!!
This data must be UNICODE encoded!!!

After analysis, I chose to save the game to use the text in a Unicode encoded text file (the next thing), and then according to the demo, the creation of an XML file, the format is consistent with the demo. Look at the following example. Note: The Unicode flag (see the contents of the XML file in a demo).

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE plist Public "-//apple//dtd plist 1.0//en" "Http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version= "1.0" >
<dict>
<key>chinese1</key>
<string> actual use is as follows </string>
<key>japanese</key>
<string> very strange </string>
<key>spanish</key>
<string> Engine header File </string>
</dict>
</plist>



With the XML file above, use the Font Builder to create the appropriate font and image file. I recommend using (I am under Windows, for Android platform) Bmfont. Is the one of the many points in the Labeltest file in the demo (http://www.angelcode.com/products/bmfont/(free, Windows only)).

To use it after downloading, you can refer to an article (http://blog.csdn.net/aa4790139/article/details/8113197).

However, the above article is only an entry level, and several questions are not specified. I use the method to display Chinese characters, but the characters have black shading. The solution is to change the 8 mentioned in the Export Options section of the article to 24. Of course, when you use Edit-select CHARS from file, you must import a text file in UTF-8 format.

In addition, the Bmfont function is quite good. Although it is generated. The Fnt file supports multiple (page) PNG files, but it is not supported for the Cocos2d-x 2.0.2 I am currently using-only one page (one PNG) is supported. Therefore, if you import a TXT file that is larger, you need to resize the position in the Export Options window (by default, 256x256), for example, to 256x512. In short, you need to adjust the image to a PNG file that is as small as possible but can hold all the characters you want to use.

Other details of the use are not said.

For the resulting PNG file, you can use a tool like Photoshop to work with your text. For example, the gold in the demo may have been processed like this. Give me a snapshot of my WIN32 program (my PS level is not good). There is no problem on the Android platform.

650) this.width=650; "src=" http://blog.itpub.net/attachments/2012/11/14466241_201211071740141.jpg "border=" 0 "alt= "14466241_201211071740141.jpg"/>

Tip: Selecting all the text in a PNG file gives me some brains and finally finds a way to do this: select-color Range-highlight.


After that, you can display your own kanji (BOTH WIN32 and android!!!) using, for example, the topmost encoding. )。


3, multi-resolution display problem


4, shortcut menu and back key operation

On the Android platform, this is relatively simple ...

5, join the advertising technology


6, customize the title name of your game software


This only needs to modify the contents of App_name in the file Strings.xml in the Res\values directory, and it is recommended to do it in eclipse.


This article is from the "Green Peak" blog, please make sure to keep this source http://zhuxianzhong.blog.51cto.com/157061/1440557

A collection of issues that must be addressed when porting Win32 games to the Android 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.