LetterboxingViewport
Combines screen and fit viewports. Similarly to ScreenViewport, world size is changed on each update (resize), so update should be generally called with true
parameter (camera should be centered). Tries to keep the passed aspect ratio by applying letterboxing - horizontal or vertical black bars.
On contrary to regular ScreenViewport, this viewport analyzes screen density (pixel per inch ratio) to preserve correct look on every platform, including mobiles. This is very convenient for GUIs (especially when using fit viewport with the same aspect ratio for game logic rendering), as they will not be scaled when the screen is resized (comparably to using similarly to screen viewport), and yet should still look acceptable on mobile devices (comparably to using fit viewport with a fixed world size).
It is advised to pair this viewport with FitViewport - LetterboxingViewport can be used for the GUI, while FitViewport is excellent for the actual (2D) game rendering.
Parameters
this is the targeted pixel per inch ratio on X axis, which allows to scale the viewport correctly on different devices. Usually about 96 for desktop and WebGL platforms, 160 for mobiles. Make sure to call updateScale after changing this variable.
targeted pixel per inch ratio on Y axis. Usually about 96 for desktop and WebGL platforms, 160 for mobiles. Make sure to call updateScale after changing this variable.
width divided by height. Will preserve this aspect ratio by applying letterboxing.
Properties
Functions
Forces update of current pixel per unit ratio according to screen density.
Forces update of current world size according to window size. Will try to keep the set aspect ratio.