Package com.badlogic.gdx.utils.viewport
Class Viewport
- java.lang.Object
-
- com.badlogic.gdx.utils.viewport.Viewport
-
- Direct Known Subclasses:
ExtendViewport,ScalingViewport,ScreenViewport
public abstract class Viewport extends java.lang.ObjectManages aCameraand determines how world coordinates are mapped to and from the screen.
-
-
Constructor Summary
Constructors Constructor Description Viewport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapply()Callsapply(boolean)with false.voidapply(boolean centerCamera)Applies the viewport to the camera and sets the glViewport.voidcalculateScissors(Matrix4 batchTransform, Rectangle area, Rectangle scissor)intgetBottomGutterHeight()Returns the bottom gutter (black bar) height in screen coordinates.CameragetCamera()intgetLeftGutterWidth()Returns the left gutter (black bar) width in screen coordinates.RaygetPickRay(float screenX, float screenY)intgetRightGutterWidth()Returns the right gutter (black bar) width in screen coordinates.intgetRightGutterX()Returns the right gutter (black bar) x in screen coordinates.intgetScreenHeight()intgetScreenWidth()intgetScreenX()intgetScreenY()intgetTopGutterHeight()Returns the top gutter (black bar) height in screen coordinates.intgetTopGutterY()Returns the top gutter (black bar) y in screen coordinates.floatgetWorldHeight()floatgetWorldWidth()Vector2project(Vector2 worldCoords)Transforms the specified world coordinate to screen coordinates.Vector3project(Vector3 worldCoords)Transforms the specified world coordinate to screen coordinates.voidsetCamera(Camera camera)voidsetScreenBounds(int screenX, int screenY, int screenWidth, int screenHeight)Sets the viewport's bounds in screen coordinates.voidsetScreenHeight(int screenHeight)Sets the viewport's height in screen coordinates.voidsetScreenPosition(int screenX, int screenY)Sets the viewport's position in screen coordinates.voidsetScreenSize(int screenWidth, int screenHeight)Sets the viewport's size in screen coordinates.voidsetScreenWidth(int screenWidth)Sets the viewport's width in screen coordinates.voidsetScreenX(int screenX)Sets the viewport's offset from the left edge of the screen.voidsetScreenY(int screenY)Sets the viewport's offset from the bottom edge of the screen.voidsetWorldHeight(float worldHeight)The virtual height of this viewport in world coordinates.voidsetWorldSize(float worldWidth, float worldHeight)voidsetWorldWidth(float worldWidth)The virtual width of this viewport in world coordinates.Vector2toScreenCoordinates(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.Vector2unproject(Vector2 screenCoords)Transforms the specified screen coordinate to world coordinates.Vector3unproject(Vector3 screenCoords)Transforms the specified screen coordinate to world coordinates.voidupdate(int screenWidth, int screenHeight)Callsupdate(int, int, boolean)with false.voidupdate(int screenWidth, int screenHeight, boolean centerCamera)Configures this viewport's screen bounds using the specified screen size and callsapply(boolean).
-
-
-
Method Detail
-
apply
public void apply()
Callsapply(boolean)with false.
-
apply
public void apply(boolean centerCamera)
Applies the viewport to the camera and sets the glViewport.- Parameters:
centerCamera- If true, the camera position is set to the center of the world.
-
update
public final void update(int screenWidth, int screenHeight)Callsupdate(int, int, boolean)with false.
-
update
public void update(int screenWidth, int screenHeight, boolean centerCamera)Configures this viewport's screen bounds using the specified screen size and callsapply(boolean). Typically called fromApplicationListener.resize(int, int)orScreen.resize(int, int).The default implementation only calls
apply(boolean).
-
unproject
public Vector2 unproject(Vector2 screenCoords)
Transforms the specified screen coordinate to world coordinates.- Returns:
- The vector that was passed in, transformed to world coordinates.
- See Also:
Camera.unproject(Vector3)
-
project
public Vector2 project(Vector2 worldCoords)
Transforms the specified world coordinate to screen coordinates.- Returns:
- The vector that was passed in, transformed to screen coordinates.
- See Also:
Camera.project(Vector3)
-
unproject
public Vector3 unproject(Vector3 screenCoords)
Transforms the specified screen coordinate to world coordinates.- Returns:
- The vector that was passed in, transformed to world coordinates.
- See Also:
Camera.unproject(Vector3)
-
project
public Vector3 project(Vector3 worldCoords)
Transforms the specified world coordinate to screen coordinates.- Returns:
- The vector that was passed in, transformed to screen coordinates.
- See Also:
Camera.project(Vector3)
-
getPickRay
public Ray getPickRay(float screenX, float screenY)
-
calculateScissors
public void calculateScissors(Matrix4 batchTransform, Rectangle area, Rectangle scissor)
-
toScreenCoordinates
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.
-
getCamera
public Camera getCamera()
-
setCamera
public void setCamera(Camera camera)
-
getWorldWidth
public float getWorldWidth()
-
setWorldWidth
public void setWorldWidth(float worldWidth)
The virtual width of this viewport in world coordinates. This width is scaled to the viewport's screen width.
-
getWorldHeight
public float getWorldHeight()
-
setWorldHeight
public void setWorldHeight(float worldHeight)
The virtual height of this viewport in world coordinates. This height is scaled to the viewport's screen height.
-
setWorldSize
public void setWorldSize(float worldWidth, float worldHeight)
-
getScreenX
public int getScreenX()
-
setScreenX
public void setScreenX(int screenX)
Sets the viewport's offset from the left edge of the screen. This is typically set byupdate(int, int, boolean).
-
getScreenY
public int getScreenY()
-
setScreenY
public void setScreenY(int screenY)
Sets the viewport's offset from the bottom edge of the screen. This is typically set byupdate(int, int, boolean).
-
getScreenWidth
public int getScreenWidth()
-
setScreenWidth
public void setScreenWidth(int screenWidth)
Sets the viewport's width in screen coordinates. This is typically set byupdate(int, int, boolean).
-
getScreenHeight
public int getScreenHeight()
-
setScreenHeight
public void setScreenHeight(int screenHeight)
Sets the viewport's height in screen coordinates. This is typically set byupdate(int, int, boolean).
-
setScreenPosition
public void setScreenPosition(int screenX, int screenY)Sets the viewport's position in screen coordinates. This is typically set byupdate(int, int, boolean).
-
setScreenSize
public void setScreenSize(int screenWidth, int screenHeight)Sets the viewport's size in screen coordinates. This is typically set byupdate(int, int, boolean).
-
setScreenBounds
public void setScreenBounds(int screenX, int screenY, int screenWidth, int screenHeight)Sets the viewport's bounds in screen coordinates. This is typically set byupdate(int, int, boolean).
-
getLeftGutterWidth
public int getLeftGutterWidth()
Returns the left gutter (black bar) width in screen coordinates.
-
getRightGutterX
public int getRightGutterX()
Returns the right gutter (black bar) x in screen coordinates.
-
getRightGutterWidth
public int getRightGutterWidth()
Returns the right gutter (black bar) width in screen coordinates.
-
getBottomGutterHeight
public int getBottomGutterHeight()
Returns the bottom gutter (black bar) height in screen coordinates.
-
getTopGutterY
public int getTopGutterY()
Returns the top gutter (black bar) y in screen coordinates.
-
getTopGutterHeight
public int getTopGutterHeight()
Returns the top gutter (black bar) height in screen coordinates.
-
-