LetterboxingViewport

class LetterboxingViewport(var targetPpiX: Float = defaultTargetPpi, var targetPpiY: Float = defaultTargetPpi, var aspectRatio: Float = 4f / 3f) : ScalingViewport

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

targetPpiX

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.

targetPpiY

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.

aspectRatio

width divided by height. Will preserve this aspect ratio by applying letterboxing.

Constructors

Link copied to clipboard
constructor(targetPpiX: Float = defaultTargetPpi, targetPpiY: Float = defaultTargetPpi, aspectRatio: Float = 4f / 3f)

Properties

Link copied to clipboard
Link copied to clipboard
var camera: Camera
Link copied to clipboard

You can directly modify unit per pixel ratio (bypassing PPI check) by modifying this value.

Link copied to clipboard

You can directly modify unit per pixel ratio (bypassing PPI check) by modifying this value.

Link copied to clipboard
var scaling: Scaling
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open fun apply()
open fun apply(p0: Boolean)
Link copied to clipboard
open fun calculateScissors(p0: Matrix4, p1: Rectangle, p2: Rectangle)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun getPickRay(p0: Float, p1: Float): Ray
Link copied to clipboard
Link copied to clipboard
open fun getRightGutterX(): Int
Link copied to clipboard
Link copied to clipboard
open fun getTopGutterY(): Int
Link copied to clipboard
open fun project(p0: Vector2): Vector2
open fun project(p0: Vector3): Vector3
Link copied to clipboard
open fun setScreenBounds(p0: Int, p1: Int, p2: Int, p3: Int)
Link copied to clipboard
open fun setScreenPosition(p0: Int, p1: Int)
Link copied to clipboard
open fun setScreenSize(p0: Int, p1: Int)
Link copied to clipboard
open fun setWorldSize(p0: Float, p1: Float)
Link copied to clipboard
open fun toScreenCoordinates(p0: Vector2, p1: Matrix4): Vector2
Link copied to clipboard
open fun unproject(p0: Vector2): Vector2
open fun unproject(p0: Vector3): Vector3
Link copied to clipboard
fun update(p0: Int, p1: Int)
open override fun update(screenWidth: Int, screenHeight: Int, centerCamera: Boolean)
Link copied to clipboard

Forces update of current pixel per unit ratio according to screen density.

Link copied to clipboard

Forces update of current world size according to window size. Will try to keep the set aspect ratio.