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:
@ Override
Protectedpixelperfectengineoptions oncreatepixelperfectengineoptions (){
Pixelperfectengineoptionspixelperfectengineoptions =
New pixelperfectengineoptions (this, zoomcamera. Class );
Pixelperfectengineoptions. setdesiredsize (800 );
Pixelperfectengineoptions
. Setscreenorientation (screenorientation. landscape_fixed );
Pixelperfectengineoptions
. Setpixelperfectmode (pixelperfectmode. change_height );
Returnpixelperfectengineoptions;
}
Copy code
Public engineoptions createengineoptions (){
Float [] screensize = This. getscreensize ();
Float screenwidth = screensize [0];
Float screenheight = screensize [1];
Float screenratio = screenwidth/screenheight;
Float camerawidth = This. mdesiredsize;
Float cameraheight = This. mdesiredsize;
If (this. mpixelperfectmode = pixelperfectmode. change_width ){
Camerawidth = This. mdesiredsize * screenratio;
} Else if (this. mpixelperfectmode = pixelperfectmode. change_height ){
Cameraheight = This. mdesiredsize/screenratio;
}
Class <?> [] Parametertypes = {float. Class, float. Class };
Object [] argparam = {0.0f, 0.0f, camerawidth, cameraheight };
Camera camera = reflectionutils. newinstance (this. mcameracls,
Parametertypes, argparam );
Engineoptions = new engineoptions (true,
This. mscreenorientation, new fillresolutionpolicy (), camera );
Engineoptions. gettouchoptions (). setneedsmultitouch (true );
Engineoptions. getaudiooptions (). setneedssound (true );
Engineoptions. getaudiooptions (). setneedsmusic (true );
Engineoptions. getrenderoptions (). setdithering (true );
Return engineoptions;
}
Copy code
Http://www.eoeandroid.com/forum-863-1.html
Www.ogengine.com