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

public abstract Class Viewport

extends Object
Class Inheritance
Known Direct Subclasses
com.badlogic.gdx.utils.viewport.ExtendViewport, com.badlogic.gdx.utils.viewport.ScalingViewport, com.badlogic.gdx.utils.viewport.ScreenViewport
Imports
com.badlogic.gdx.ApplicationListener, .Gdx, .Screen, com.badlogic.gdx.graphics.Camera, com.badlogic.gdx.graphics.glutils.HdpiUtils, com.badlogic.gdx.math.Matrix4, .Rectangle, .Vector2, .Vector3, com.badlogic.gdx.math.collision.Ray, com.badlogic.gdx.scenes.scene2d.utils.ScissorStack

Manages a Camera and determines how world coordinates are mapped to and from the screen.
Authors
Daniel Holderbaum, Nathan Sweet

Field Summary

Modifier and TypeField and Description
private Camera
private int
private int
private int
private int
private final Vector3
private float
private float

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
apply()

Calls apply(boolean) with false.

public void
apply(boolean
If true, the camera position is set to the center of the world.
centerCamera
)

Applies the viewport to the camera and sets the glViewport.

public void
calculateScissors(Matrix4 batchTransform, Rectangle area, Rectangle scissor)

public int
getBottomGutterHeight()

Returns the bottom gutter (black bar) height in screen coordinates.

public Camera
public int
getLeftGutterWidth()

Returns the left gutter (black bar) width in screen coordinates.

public Ray
getPickRay(float touchX, float touchY)

public int
getRightGutterWidth()

Returns the right gutter (black bar) width in screen coordinates.

public int
getRightGutterX()

Returns the right gutter (black bar) x in screen coordinates.

public int
public int
public int
public int
public int
getTopGutterHeight()

Returns the top gutter (black bar) height in screen coordinates.

public int
getTopGutterY()

Returns the top gutter (black bar) y in screen coordinates.

public float
public float
public Vector2

Returns:

The vector that was passed in, transformed to screen coordinates.
project
(Vector2 worldCoords)

Transforms the specified world coordinate to screen coordinates.

public Vector3

Returns:

The vector that was passed in, transformed to screen coordinates.
project
(Vector3 worldCoords)

Transforms the specified world coordinate to screen coordinates.

public void
setCamera(Camera camera)

public void
setScreenBounds(int screenX, int screenY, int screenWidth, int screenHeight)

Sets the viewport's bounds in screen coordinates.

public void
setScreenHeight(int screenHeight)

Sets the viewport's height in screen coordinates.

public void
setScreenPosition(int screenX, int screenY)

Sets the viewport's position in screen coordinates.

public void
setScreenSize(int screenWidth, int screenHeight)

Sets the viewport's size in screen coordinates.

public void
setScreenWidth(int screenWidth)

Sets the viewport's width in screen coordinates.

public void
setScreenX(int screenX)

Sets the viewport's offset from the left edge of the screen.

public void
setScreenY(int screenY)

Sets the viewport's offset from the bottom edge of the screen.

public void
setWorldHeight(float worldHeight)

The virtual height of this viewport in world coordinates.

public void
setWorldSize(float worldWidth, float worldHeight)

public void
setWorldWidth(float worldWidth)

The virtual width of this viewport in world coordinates.

public Vector2
toScreenCoordinates(Vector2 worldCoords, Matrix4 transformMatrix)

Transforms a point to real screen coordinates (as opposed to OpenGL ES window coordinates), where the origin is in the top left and the the y-axis is pointing downwards.

public Vector2

Returns:

The vector that was passed in, transformed to world coordinates.
unproject
(Vector2 touchCoords)

Transforms the specified touch coordinate to world coordinates.

public Vector3

Returns:

The vector that was passed in, transformed to world coordinates.
unproject
(Vector3 screenCoords)

Transforms the specified screen coordinate to world coordinates.

public final void
update(int screenWidth, int screenHeight)

Calls update(int, int, boolean) with false.

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

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cameraback to summary
private Camera camera
screenHeightback to summary
private int screenHeight
screenWidthback to summary
private int screenWidth
screenXback to summary
private int screenX
screenYback to summary
private int screenY
tmpback to summary
private final Vector3 tmp
worldHeightback to summary
private float worldHeight
worldWidthback to summary
private float worldWidth

Constructor Detail

Viewportback to summary
public Viewport()

Method Detail

applyback to summary
public void apply()

Calls apply(boolean) with false.

applyback to summary
public void apply(boolean centerCamera)

Applies the viewport to the camera and sets the glViewport.

Parameters
centerCamera:boolean

If true, the camera position is set to the center of the world.

calculateScissorsback to summary
public void calculateScissors(Matrix4 batchTransform, Rectangle area, Rectangle scissor)
See Also
ScissorStack#calculateScissors(Camera, float, float, float, float, Matrix4, Rectangle, Rectangle)
getBottomGutterHeightback to summary
public int getBottomGutterHeight()

Returns the bottom gutter (black bar) height in screen coordinates.

getCameraback to summary
public Camera getCamera()
getLeftGutterWidthback to summary
public int getLeftGutterWidth()

Returns the left gutter (black bar) width in screen coordinates.

getPickRayback to summary
public Ray getPickRay(float touchX, float touchY)
See Also
Camera#getPickRay(float, float, float, float, float, float)
getRightGutterWidthback to summary
public int getRightGutterWidth()

Returns the right gutter (black bar) width in screen coordinates.

getRightGutterXback to summary
public int getRightGutterX()

Returns the right gutter (black bar) x in screen coordinates.

getScreenHeightback to summary
public int getScreenHeight()
getScreenWidthback to summary
public int getScreenWidth()
getScreenXback to summary
public int getScreenX()
getScreenYback to summary
public int getScreenY()
getTopGutterHeightback to summary
public int getTopGutterHeight()

Returns the top gutter (black bar) height in screen coordinates.

getTopGutterYback to summary
public int getTopGutterY()

Returns the top gutter (black bar) y in screen coordinates.

getWorldHeightback to summary
public float getWorldHeight()
getWorldWidthback to summary
public float getWorldWidth()
projectback to summary
public Vector2 project(Vector2 worldCoords)

Transforms the specified world coordinate to screen coordinates.

Returns:Vector2

The vector that was passed in, transformed to screen coordinates.

See Also
Camera#project(Vector3)
projectback to summary
public Vector3 project(Vector3 worldCoords)

Transforms the specified world coordinate to screen coordinates.

Returns:Vector3

The vector that was passed in, transformed to screen coordinates.

See Also
Camera#project(Vector3)
setCameraback to summary
public void setCamera(Camera camera)
setScreenBoundsback to summary
public void setScreenBounds(int screenX, int screenY, int screenWidth, int screenHeight)

Sets the viewport's bounds in screen coordinates. This is typically set by update(int, int, boolean).

setScreenHeightback to summary
public void setScreenHeight(int screenHeight)

Sets the viewport's height in screen coordinates. This is typically set by update(int, int, boolean).

setScreenPositionback to summary
public void setScreenPosition(int screenX, int screenY)

Sets the viewport's position in screen coordinates. This is typically set by update(int, int, boolean).

setScreenSizeback to summary
public void setScreenSize(int screenWidth, int screenHeight)

Sets the viewport's size in screen coordinates. This is typically set by update(int, int, boolean).

setScreenWidthback to summary
public void setScreenWidth(int screenWidth)

Sets the viewport's width in screen coordinates. This is typically set by update(int, int, boolean).

setScreenXback to summary
public void setScreenX(int screenX)

Sets the viewport's offset from the left edge of the screen. This is typically set by update(int, int, boolean).

setScreenYback to summary
public void setScreenY(int screenY)

Sets the viewport's offset from the bottom edge of the screen. This is typically set by update(int, int, boolean).

setWorldHeightback to summary
public void setWorldHeight(float worldHeight)

The virtual height of this viewport in world coordinates. This height is scaled to the viewport's screen height.

setWorldSizeback to summary
public void setWorldSize(float worldWidth, float worldHeight)
setWorldWidthback to summary
public void setWorldWidth(float worldWidth)

The virtual width of this viewport in world coordinates. This width is scaled to the viewport's screen width.

toScreenCoordinatesback to summary
public Vector2 toScreenCoordinates(Vector2 worldCoords, Matrix4 transformMatrix)

Transforms a point to real screen coordinates (as opposed to OpenGL ES window coordinates), where the origin is in the top left and the the y-axis is pointing downwards.

unprojectback to summary
public Vector2 unproject(Vector2 touchCoords)

Transforms the specified touch coordinate to world coordinates. The x- and y-coordinate of vec are assumed to be in touch coordinates (origin is the top left corner, y * pointing down, x pointing to the right)

Returns:Vector2

The vector that was passed in, transformed to world coordinates.

See Also
Camera#unproject(Vector3)
unprojectback to summary
public Vector3 unproject(Vector3 screenCoords)

Transforms the specified screen coordinate to world coordinates.

Returns:Vector3

The vector that was passed in, transformed to world coordinates.

See Also
Camera#unproject(Vector3)
updateback to summary
public final void update(int screenWidth, int screenHeight)

Calls update(int, int, boolean) with false.

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

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).