Mobile Game Engine libgdx-1.2 resolution adaptive, mobile game libgdx-1.2
Since libgdx 1.0, the stage resolution adaptive method has changed.
Let's look at the stage construction method:
public Stage (Viewport viewport) { this(viewport, null);}
You must create your own Viewport manually.
new Stage((new ScalingViewport(Scaling.stretch, width, height, new OrthographicCamera())));
ScalingViewport: scalable Viewing Angle
Scaling. stretch: stretch by screen size
Width: screen width (the actual screen width of your game, not the screen width)
Height: screen height
OrthographicCamera: Specifies a projection camera.
Can mobile games adapt to the resolution of mobile phones ??
Mobile games should not automatically adapt to resolution due to the following reasons:
1. mobile Games Written in kjava generally have different mobile phone types on the website when you download them. Even if the same mobile phone type is different, the same mobile phone code should be generic, so the downloaded version must be different because the screen size of the mobile phone is different, and the other part of the game should be consistent.
2. from the perspective of the image resolution, if a small image changes its size (px value), the display will be distorted if it is too large. The game itself is displaying the image, but the screen size is fixed, so it should not.
However, this is not absolute. If the screen size of the mobile phone can be detected when the program is executed, and the game resources have corresponding size images, the system can automatically adapt to the situation, however, the game capacity will be too large to meet the small and exquisite features of mobile games.
Therefore, mobile games cannot automatically adapt to resolution.
Does android games also support adaptive resolution?
The xml layout is adaptive. If you play games, you have to make your own layout. If you have to make them adaptive, you can do that at the cost of losing the game processing efficiency.