How ogengine supports multiple resolutions

Source: Internet
Author: User

For screen adaptation of andengine, ratioresolutionpolicy is usually used to stretch the screen. However, when the game resolution is different from the width and height of the mobile phone resolution, black areas are inevitable, this affects the gaming experience. Currently, the ogengine Open Source engine has solved this problem and can achieve a full screen adaptive screen.

Game Design Resolution:

We define the game resolution by ourselves (for example, 800 × 480), and then the UI draws based on the resolution.

Mobile phone screen resolution: the resolution of the mobile phone's own Screen

Expected resolution = game design resolution

Actual resolution = mobile phone screen resolution

First, determine whether it is a horizontal screen game or a vertical screen game. Assume that the mobile phone number is 320 × 480, It is a vertical screen game, and the game design resolution is 480 × 800.

For example, to keep the width unchanged, high adaptation. Assume that the image provided by the UI is 480x800.

Screen aspect ratio = actual resolution width (320)/actual resolution height (480) = expected resolution width (480)/expected resolution height

We can see that the expected resolution height is equal to 720. Because the UI gives the image a height of 800, the blank Part 80 = 800-720 is the one with no shadow in the image.


The following information is displayed on the mobile phone:



The following code is used:

  1. @ Override

  2. Protectedpixelperfectengineoptions oncreatepixelperfectengineoptions (){

  3. Pixelperfectengineoptionspixelperfectengineoptions =

  4. New pixelperfectengineoptions (this, zoomcamera. Class );

  5. Pixelperfectengineoptions. setdesiredsize (800 );

  6. Pixelperfectengineoptions

  7. . Setscreenorientation (screenorientation. landscape_fixed );

  8. Pixelperfectengineoptions

  9. . Setpixelperfectmode (pixelperfectmode. change_height );

  10. Returnpixelperfectengineoptions;

  11. }

Copy code

  1. Public engineoptions createengineoptions (){

  2. Float [] screensize = This. getscreensize ();

  3. Float screenwidth = screensize [0];

  4. Float screenheight = screensize [1];

  5. Float screenratio = screenwidth/screenheight;

  6. Float camerawidth = This. mdesiredsize;

  7. Float cameraheight = This. mdesiredsize;

  8. If (this. mpixelperfectmode = pixelperfectmode. change_width ){

  9. Camerawidth = This. mdesiredsize * screenratio;

  10. } Else if (this. mpixelperfectmode = pixelperfectmode. change_height ){

  11. Cameraheight = This. mdesiredsize/screenratio;

  12. }

  13. Class <?> [] Parametertypes = {float. Class, float. Class };

  14. Object [] argparam = {0.0f, 0.0f, camerawidth, cameraheight };

  15. Camera camera = reflectionutils. newinstance (this. mcameracls,

  16. Parametertypes, argparam );

  17. Engineoptions = new engineoptions (true,

  18. This. mscreenorientation, new fillresolutionpolicy (), camera );

  19. Engineoptions. gettouchoptions (). setneedsmultitouch (true );

  20. Engineoptions. getaudiooptions (). setneedssound (true );

  21. Engineoptions. getaudiooptions (). setneedsmusic (true );

  22. Engineoptions. getrenderoptions (). setdithering (true );

  23. Return engineoptions;

  24. }

Copy code

Http://www.eoeandroid.com/forum-863-1.html

Www.ogengine.com



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.