APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.utils.viewport

public Class ScreenViewport

extends Viewport
Class Inheritance
Imports
com.badlogic.gdx.graphics.Camera, .OrthographicCamera

A viewport where the world size is based on the size of the screen. By default 1 world unit == 1 screen pixel, but this ratio can be changed.
Authors
Daniel Holderbaum, Nathan Sweet

Field Summary

Modifier and TypeField and Description
private float

Constructor Summary

AccessConstructor and Description
public
ScreenViewport()

Creates a new viewport using a new OrthographicCamera.

public

Method Summary

Modifier and TypeMethod and Description
public float
public void
setUnitsPerPixel(float unitsPerPixel)

Sets the number of pixels for each world unit.

public void
update(int screenWidth, int screenHeight, boolean centerCamera)

Overrides com.badlogic.gdx.utils.viewport.Viewport.update.

Configures this viewport's screen bounds using the specified screen size and calls apply(boolean).

Inherited from com.badlogic.gdx.utils.viewport.Viewport:
applyapplycalculateScissorsgetBottomGutterHeightgetCameragetLeftGutterWidthgetPickRaygetRightGutterWidthgetRightGutterXgetScreenHeightgetScreenWidthgetScreenXgetScreenYgetTopGutterHeightgetTopGutterYgetWorldHeightgetWorldWidthprojectprojectsetCamerasetScreenBoundssetScreenHeightsetScreenPositionsetScreenSizesetScreenWidthsetScreenXsetScreenYsetWorldHeightsetWorldSizesetWorldWidthtoScreenCoordinatesunprojectunprojectupdate

Field Detail

unitsPerPixelback to summary
private float unitsPerPixel

Constructor Detail

ScreenViewportback to summary
public ScreenViewport()

Creates a new viewport using a new OrthographicCamera.

ScreenViewportback to summary
public ScreenViewport(Camera camera)

Method Detail

getUnitsPerPixelback to summary
public float getUnitsPerPixel()
setUnitsPerPixelback to summary
public void setUnitsPerPixel(float unitsPerPixel)

Sets the number of pixels for each world unit. Eg, a scale of 2.5 means there are 2.5 world units for every 1 screen pixel. Default is 1.

updateback to summary
public void update(int screenWidth, int screenHeight, boolean centerCamera)

Overrides com.badlogic.gdx.utils.viewport.Viewport.update.

Doc from com.badlogic.gdx.utils.viewport.Viewport.update.

Configures this viewport's screen bounds using the specified screen size and calls apply(boolean). Typically called from ApplicationListener#resize(int, int) or Screen#resize(int, int).

The default implementation only calls apply(boolean).