libgdx screen adaptation analysis

libgdx has a concept of virtual resolution. When we initialize Stage, we can pass in the virtual resolution we
defined ,
new Stage(new ScalingViewport(Scaling.stretch, 480, 800, new OrthographicCamera()));
Scaling.stretch this is your adaptation strategy. The adaptation strategy can choose the following:


<pre name="code" class="java"> /** Scales the source to fit the target while keeping the same aspect ratio. This may cause the source to be smaller than the
* target in one direction. */
fit,
/** Scales the source to fill the target while keeping the same aspect ratio. This may cause the source to be larger than the
* target in one direction. * /
fill,

//fillX This adaptation strategy is: the width is the X direction, scale to the same size as the screen, that is, fill the target in the x direction, and the height is the Y direction
// The top is scaled according to the scaling ratio of the X direction ( keeping the same aspect ratio), so that the graphics will not be deformed, thinking that the scaling ratios in the X and Y directions are the same,
//There will be a problem at that time, that is, there may be black borders in the Y direction, or it may exceed the display screen. This kind of fixed width can be used. Do something with the height.
//For example, we calculate the virtual height according to the scaling ratio of the width, and then place our pictures according to this virtual height.
/** Scales the source to fill the target in the x direction while keeping the same aspect ratio. This may cause the source to be
* smaller or larger than the target in the y direction. */
fillX,
/** Scales the source to fill the target in the y direction while keeping the same aspect ratio. This may cause the source to be
* smaller or larger than the target in the x direction. */
fillY,

//stretch both length and width fully scaled to the screen The same size, which may cause deformation, such as a 720*1280 screen, the scaling ratio in the height direction is 1208/800 = 1.6
//The scaling ratio in the width direction is 720/480 = 1.5, then, because the scaling ratios in the length and width directions are different, When our picture is displayed on
// the screen, there will be deformation and stretching.
/** Scales the source to fill the target. This may cause the source to not keep the same aspect ratio. */
stretch,
/** Scales the source to fill the target in the x direction, without changing the y direction. This may cause the source to not
* keep the same aspect ratio. */
stretchX,
/** Scales the source to fill the target in the y direction, without changing the x direction. This may cause the source to not
* keep the same aspect ratio ratio. */
stretchY,
/** The source is not scaled. */
none; 480 and


800 are virtual resolutions. When we make pictures, we can draw according to this
size , and when we make the interface, when we lay out the layout , and also according to this size, place our UI elements, when displayed on the screen, they will be scaled according to our adaptation strategy,
and then displayed on the screen.
http://www.mamicode.com/info-detail-566357.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326236061&siteId=291194637