For a long time by the screen adaptive make very faint, here summarizes the recent learning sentiment.
First understand several concepts:
1, screen resolution (mobile phone commonly used 1280*720,800*480, etc.)
2, picture resolution (Image size 256 * 256, etc.)
Game development, the provision of a good standard of suitable models, here models to 1280*720 For example, all the pictures produced on the 1280*720 model will not have any scaling. Ngui Uiroot can choose the scaling Type, here to choose fixedsize, at this time you can enter the height of the standard model in the manaul height bar, so enter 720 here, Subsequent screen adaptations will be scaled at this height. Suppose we create a sprite under a panel and position it in a position where the sprite is <320,180,0>,sprite in size 100*100. When the UI is placed into a 480*320 phone, the size of the sprite is scaled according to the current device height:
Scaled Sprite size = device height/Standard Resolution Height * <sprite width, Sprite height >, here scaled size: 320/720 * <100,100> = <44.44,44.44>
Position after scaling = device height/Standard Resolution height * <x,y,z>, here scaled size: 320/720 * <320,180,0> = <142,80,0>
This completes a screen fit.
Another example, if the size of the picture is 1280*720, the position is <0,0,0>, at the standard resolution, the picture is exactly the same size as the screen, put the picture in 480*320 's phone,
Scaled size 320/720*<1280,720> = <568,320>
Post-zoom position 320/720* <0,0,0> = <0,0,0>
The screen size is <480,320>, so the sides of the picture will be trimmed. The aspect ratio of the 1280*720 is 1.7:1, and the 480*320 aspect ratio is 1.5:1, so the height-based adaptive discomfort is not suitable for smaller models with a wide ratio.
To solve this problem, you can use a width-based adaptive approach (the principle is consistent with height-based scaling).
Another problem adaptive to solve is the problem of position adaptation of the sprite, assuming that a sprite wants to lean on the leftmost side of the screen, the size of the sprite is 100*100, and the sprite can be hung on the Uianchor script, Container Select Uiroot,relative Offset in the x =-0.5 (for the leftmost screen, 0 for the middle, 0.5 for the rightmost), Pixel offset in x to select 1/2 of the picture size, Here is 50 (representing the picture center is just half the picture from the edge of the screen, that is, the picture is close to the edge of the screen), so that no matter how to zoom, the image position is far from the left side of the screen image width, you can achieve the image position adaptive.
NGUI Adaptive (based on fixedsize)