Class Viewport

java.lang.Object
arc.util.viewport.Viewport
Direct Known Subclasses:
ExtendViewport, ScalingViewport, ScreenViewport

public abstract class Viewport extends Object
Manages a Camera and determines how world coordinates are mapped to and from the screen.
  • Constructor Details

    • Viewport

      public Viewport()
  • Method Details

    • apply

      public void apply()
      Calls apply(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)
      Calls update(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 calls apply(boolean). Typically called from ApplicationListener.resize(int, int)

      The default implementation only calls apply(boolean).

    • unproject

      public Vec2 unproject(Vec2 screenCoords)
      Transforms the specified screen coordinate to world coordinates.
      Returns:
      The vector that was passed in, transformed to world coordinates.
      See Also:
    • project

      public Vec2 project(Vec2 worldCoords)
      Transforms the specified world coordinate to screen coordinates.
      Returns:
      The vector that was passed in, transformed to screen coordinates.
      See Also:
    • calculateScissors

      public void calculateScissors(Mat batchTransform, Rect area, Rect scissor)
      See Also:
    • toScreenCoordinates

      public Vec2 toScreenCoordinates(Vec2 worldCoords, Mat 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 by update(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 by update(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 by update(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 by update(int, int, boolean).
    • setScreenPosition

      public void setScreenPosition(int screenX, int screenY)
      Sets the viewport's position in screen coordinates. This is typically set by update(int, int, boolean).
    • setScreenSize

      public void setScreenSize(int screenWidth, int screenHeight)
      Sets the viewport's size in screen coordinates. This is typically set by update(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 by update(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.