[Android game development 21] Android OS device lie resolution solution! And briefly explain how to use the game engine!

Source: Internet
Author: User

Li huaming himiOriginal, reprinted must be explicitly noted:
Reprinted from[Heimi gamedev block]Link: http://www.himigame.com/android-game/356.html


A question asked by the brothers in the group just now, I will share it with you here: the new emulator is configured as a device simulator with a resolution of 800*480 FOR THE waga800, when we obtain its height and width in our program, we find that it is always 320*533, obviously the system is lying to us! For example:



Below is the original official document:




So why does the system lie about its resolution? What is its role?


In short, after sdk1.6 (SDK version 4), Android adds the new feature"Multi-screen support"The so-called new function is to make our games and software run smoothly and play well at different resolutions and on different models, thus reducing our porting workload, second, to better reflect the increasing momentum of Android.


Adaptive effects include: (WVGA high density (left), medium density (hvga), low density and qvga (right)


In terms of different resolutions, I want to play meide. A game and software can be used in two ways. One is that we make adaptive screen games when playing games, for example, we take coordinates based on the screen width, height, image width, height, and so on, rather than writing the dead position coordinates. The second is the adaptive technology of Android OS after 1.6;


However, in some cases, it is clear that android does not provide this kind of adaptive feature ,(In fact, this is similar to the current game engine. Many people are asking me what engine is used to develop the game. In fact, the company has its own engine. I write games on my own and generally do not use others' engines (I write engines on my own), because no game engine is suitable for all types of game development. For example, how can I use an RPG Engine to create a puzzle link? --... Of course, there are already a lot of game development engines on the market, but the use of other game engines, for development, although the development efficiency, shorten the development cycle, but it is a headache for its scalability. So ~ We recommend that you absorb the knowledge and technology of these open-source engines and organize your own game engine. After all, it is much easier to expand your game engine! Instead, we can't use what we call to use and use other people's ways of thinking in our minds.Back to the topic, I just mentioned that sometimes we don't want to use the self-adaptation Provided by Android OS, but write self-adaptation, which is more flexible.


The following describes how to avoid the adaptive method of Android OS:


Let's take a look at the official article:



Here is a piece of text taken from the official document. Here we are talking about the difference between the android SDK version 4 or earlier and the version 5 or later;

So we can see from here that android SDK 1.6 (version 4) does not support self-adaptation, so there is a solution;



We only needAndroidmainfest, Define<Uses-SDK Android: minsdkversion = "4"/>OK!


<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "com. desmo. testad "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <br/> <application Android: icon =" @ drawable/icon "Android: label = "@ string/app_name"> <br/> <activity Android: Name = ". test "Android: Label =" @ string/app_name "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. action. main "/> <br/> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> <br/> </Application> <br/> <uses-SDK Android: minsdkversion = "4"/> <br/> </manifest> 


Then let's take a look at the modified XML operation:



This is normal. Here I want to apologize to everyone. As you can see, there have been no updates recently. The main reason is that I went back to my hometown for the New Year and just returned to work on my first day, the second point is that due to publishing a book, the contract for Tsinghua press has been signed, and a book on Android game development will be completed in the first half of the year ~ Everyone understands me. Of course, I must update my blog, but it will not be as fast as before.

The 21 articles I have written are basically useful for learning game development. I hope you will take a closer look, because many people ask what they have written. If you have any questions or questions, you can come to the Group to communicate and learn from each other.


Click OK and write it here. You will finish the books as soon as possible so that you can see them earlier.


_________________ >>>>>>>>>>>>>>>>>>>>>>>>>>>>


This article adds: Some netizens still have two questions. Next we will analyze them one by one;


"Generally, the density of 240x240/160 is, and the resulting coefficient is,

Therefore, the correct pixel is multiplied by 1.5 In 320x533, which must be calculated based on the screen's density.


This paragraph is correct. (The formula has been written in the official API documentation) Android SDK 1.6 and above can be used through canvas. getdensity (); get the density, canvas. setdensity (240); set the density, but many friends who have set the density know that this does not have any effect at all. Then I want to use the ratio to scale the canvas and process the canvas so that it returns to the correct resolution (pixel). Although the goal is achieved, it is found that the distortion is very serious. Therefore, I think it is convenient and practical to define minsdkversion using XML. However, another problem occurs:




"<Uses-SDK Android: minsdkversion = "4"/>. After this sentence is added, SDK = 3 (that is, when SDK 1.5 is used ),

Can't the created APK be installed?


Yes, once we have defined the minimum version of the application program, none of the lower versions will be able to install the application, but I do not have a good solution besides using the density ratio.


Summary:First, there are two drawbacks to this solution:

First, the program cannot be installed under SDK 1.6.

Second, it affects the features of higher versions. For example, our Bluetooth APIs are available only in the 2.0 + version.


However, the density ratio can be used, but it is best not to. After all, the distortion is serious.



Some kids shoes use androidmanifest. XML in the project to define these attributes:

Android: normalscreens = "true"

Android: smallscreens = "true"

Android: anydensity = "true"

These are some switches, such as whether to support small screens, whether to support any density, etc., but by trying to find that the effect is not ideal, or even ineffective;

It may be that the method used is incorrect. We hope that the children's shoes that have been thoroughly explored in this area can share their experiences for discussion and study;

If you have any suggestions or methods, please let me know. Thank you.











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.