java.lang.Object
de.gurkenlabs.litiengine.graphics.Camera
All Implemented Interfaces:
ICamera, IUpdateable
Direct Known Subclasses:
FreeFlightCamera, PositionLockCamera

public class Camera
extends java.lang.Object
implements ICamera
  • Nested Class Summary

    Nested classes/interfaces inherited from interface de.gurkenlabs.litiengine.graphics.ICamera

    ICamera.FocusChangedListener, ICamera.ZoomChangedListener
  • Constructor Summary

    Constructors 
    ConstructorDescription
    Camera()
    Instantiates a new Camera instance.
  • Method Summary

    Modifier and TypeMethodDescription
    protected java.awt.geom.Point2DclampToMap​(java.awt.geom.Point2D focus) 
    AligngetClampAlign() 
    ValigngetClampValign() 
    java.awt.geom.Point2DgetFocus()
    Gets the map location that is focused by this camera.
    java.awt.geom.Point2DgetMapLocation​(java.awt.geom.Point2D viewPortLocation)
    Converts a point in screen coordinates into a map location.
    doublegetPixelOffsetX()
    Gets the x coordinate of the viewport's origin.
    doublegetPixelOffsetY()
    Gets the y coordinate of the viewport's origin.
    java.awt.geom.Rectangle2DgetViewport()
    Gets the camera's viewport region, in screen coordinates.
    java.awt.geom.Point2DgetViewportDimensionCenter​(IEntity entity)
    Gets the center of the entity, in screen coordinates.
    protected doublegetViewportHeight() 
    java.awt.geom.Point2DgetViewportLocation​(double x, double y)
    Converts a location in map coordinates into screen coordinates.
    protected doublegetViewportWidth() 
    floatgetZoom()
    The zoom factor of this camera.
    booleanisClampToMap()
    Returns whether this camera will clamp the viewport to the bounds of the map.
    voidonFocus​(ICamera.FocusChangedListener listener)
    Adds the specified focus changed listener to receive events when the focus of this camera changed.
    voidonZoom​(ICamera.ZoomChangedListener listener)
    Adds the specified zoom changed listener to receive events when the zoom of this camera changed.
    voidpan​(double x, double y, int duration)
    Pans the camera over the specified duration (in frames) to the target location, after accounting for modifications such as clamping to the map.
    voidpan​(java.awt.geom.Point2D focus, int duration)
    Pans the camera over the specified duration (in frames) to the target location, after accounting for modifications such as clamping to the map.
    protected intpanTime() 
    voidremoveFocusListener​(ICamera.FocusChangedListener listener)
    Removes the specified focus changed listener.
    voidremoveZoomListener​(ICamera.ZoomChangedListener listener)
    Removes the specified zoom changed listener.
    voidsetClampAlign​(Align align, Valign valign) 
    voidsetClampToMap​(boolean clampToMap)
    Set the camera to clamp the viewport to the bounds of the map.
    voidsetFocus​(double x, double y)
    Focuses the camera on a given point.
    voidsetFocus​(java.awt.geom.Point2D focus)
    Focuses the camera on a given point.
    voidsetZoom​(float targetZoom, int delay)
    Changes the camera's zoom over the specified duration (in frames) to the target zoom.
    voidshake​(double intensity, int delay, int shakeDuration)
    Shake the camera for the specified duration (in frames).
    voidupdate()
    This method is called by the game loop on all objects that are attached to the loop.
    voidupdateFocus()
    Currently an update function for the shake effect.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface de.gurkenlabs.litiengine.graphics.ICamera

    getRenderScale, getViewportLocation, getViewportLocation
  • Constructor Details

    • Camera

      public Camera()
      Instantiates a new Camera instance.
  • Method Details

    • getFocus

      public java.awt.geom.Point2D getFocus()
      Description copied from interface: ICamera
      Gets the map location that is focused by this camera.
      Specified by:
      getFocus in interface ICamera
      Returns:
      the focus's location in map coordinates
    • getMapLocation

      public java.awt.geom.Point2D getMapLocation​(java.awt.geom.Point2D viewPortLocation)
      Description copied from interface: ICamera
      Converts a point in screen coordinates into a map location.
      Specified by:
      getMapLocation in interface ICamera
      Parameters:
      viewPortLocation - the point in screen coordinates
      Returns:
      the map location
    • getPixelOffsetX

      public double getPixelOffsetX()
      Description copied from interface: ICamera
      Gets the x coordinate of the viewport's origin.
      Specified by:
      getPixelOffsetX in interface ICamera
      Returns:
      the offset, in screen coordinates
    • getPixelOffsetY

      public double getPixelOffsetY()
      Description copied from interface: ICamera
      Gets the y coordinate of the viewport's origin.
      Specified by:
      getPixelOffsetY in interface ICamera
      Returns:
      the offset, in screen coordinates
    • getViewport

      public java.awt.geom.Rectangle2D getViewport()
      Description copied from interface: ICamera
      Gets the camera's viewport region, in screen coordinates.
      Specified by:
      getViewport in interface ICamera
      Returns:
      the viewport region, in screen coordinates
    • getViewportDimensionCenter

      public java.awt.geom.Point2D getViewportDimensionCenter​(IEntity entity)
      Description copied from interface: ICamera
      Gets the center of the entity, in screen coordinates.
      Specified by:
      getViewportDimensionCenter in interface ICamera
      Parameters:
      entity - The entity to retrieve the dimension center for.
      Returns:
      the center, in screen coordinates
    • getViewportLocation

      public java.awt.geom.Point2D getViewportLocation​(double x, double y)
      Description copied from interface: ICamera
      Converts a location in map coordinates into screen coordinates.
      Specified by:
      getViewportLocation in interface ICamera
      Parameters:
      x - The x-coordinate of the viewport location.
      y - The y-coordinate of the viewport location.
      Returns:
      the screen location
    • getZoom

      public float getZoom()
      Description copied from interface: ICamera
      The zoom factor of this camera.
      Specified by:
      getZoom in interface ICamera
      Returns:
      the scale factor
    • onZoom

      public void onZoom​(ICamera.ZoomChangedListener listener)
      Description copied from interface: ICamera
      Adds the specified zoom changed listener to receive events when the zoom of this camera changed.
      Specified by:
      onZoom in interface ICamera
      Parameters:
      listener - The listener to add.
    • removeZoomListener

      public void removeZoomListener​(ICamera.ZoomChangedListener listener)
      Description copied from interface: ICamera
      Removes the specified zoom changed listener.
      Specified by:
      removeZoomListener in interface ICamera
      Parameters:
      listener - The listener to add.
    • onFocus

      public void onFocus​(ICamera.FocusChangedListener listener)
      Description copied from interface: ICamera
      Adds the specified focus changed listener to receive events when the focus of this camera changed.
      Specified by:
      onFocus in interface ICamera
      Parameters:
      listener - The listener to add.
    • removeFocusListener

      public void removeFocusListener​(ICamera.FocusChangedListener listener)
      Description copied from interface: ICamera
      Removes the specified focus changed listener.
      Specified by:
      removeFocusListener in interface ICamera
      Parameters:
      listener - The listener to add.
    • setFocus

      public void setFocus​(java.awt.geom.Point2D focus)
      Description copied from interface: ICamera
      Focuses the camera on a given point.
      Specified by:
      setFocus in interface ICamera
      Parameters:
      focus - the point, in map coordinates
    • setFocus

      public void setFocus​(double x, double y)
      Description copied from interface: ICamera
      Focuses the camera on a given point.
      Specified by:
      setFocus in interface ICamera
      Parameters:
      x - the x coordinate of the point, in map coordinates
      y - the y coordinate of the point, in map coordinates
    • setZoom

      public void setZoom​(float targetZoom, int delay)
      Description copied from interface: ICamera
      Changes the camera's zoom over the specified duration (in frames) to the target zoom.
      Specified by:
      setZoom in interface ICamera
      Parameters:
      targetZoom - the new zoom scale
      delay - the number of frames between this call and when the zoom completes
    • shake

      public void shake​(double intensity, int delay, int shakeDuration)
      Description copied from interface: ICamera
      Shake the camera for the specified duration (in frames). The way the camera shakes is implementation defined.
      Specified by:
      shake in interface ICamera
      Parameters:
      intensity - The intensity of the screen shake effect.
      delay - The delay before the effect starts.
      shakeDuration - The duration of the effect.
    • update

      public void update()
      Description copied from interface: IUpdateable
      This method is called by the game loop on all objects that are attached to the loop. It's called on every tick of the loop and the frequency can be configured using the ClientConfiguration.
      Specified by:
      update in interface IUpdateable
      See Also:
      ClientConfiguration.setMaxFps(int)
    • updateFocus

      public void updateFocus()
      Description copied from interface: ICamera
      Currently an update function for the shake effect.
      Specified by:
      updateFocus in interface ICamera
    • isClampToMap

      public boolean isClampToMap()
      Description copied from interface: ICamera
      Returns whether this camera will clamp the viewport to the bounds of the map.
      Specified by:
      isClampToMap in interface ICamera
      Returns:
      True if the camera viewport is currently clamped to the map boundaries; otherwise false.
    • setClampToMap

      public void setClampToMap​(boolean clampToMap)
      Description copied from interface: ICamera
      Set the camera to clamp the viewport to the bounds of the map.
      Specified by:
      setClampToMap in interface ICamera
      Parameters:
      clampToMap - A flag indicating whether the camera viewport should be clamped to the map boundaries.
    • setClampAlign

      public void setClampAlign​(Align align, Valign valign)
      Specified by:
      setClampAlign in interface ICamera
    • getClampAlign

      public Align getClampAlign()
      Specified by:
      getClampAlign in interface ICamera
    • getClampValign

      public Valign getClampValign()
      Specified by:
      getClampValign in interface ICamera
    • pan

      public void pan​(java.awt.geom.Point2D focus, int duration)
      Description copied from interface: ICamera
      Pans the camera over the specified duration (in frames) to the target location, after accounting for modifications such as clamping to the map. Event listeners attached to this camera are notified when the pan completes.
      Specified by:
      pan in interface ICamera
      Parameters:
      focus - the new focus for the camera once the panning is complete
      duration - the number of frames between this call and when the pan completes
    • pan

      public void pan​(double x, double y, int duration)
      Description copied from interface: ICamera
      Pans the camera over the specified duration (in frames) to the target location, after accounting for modifications such as clamping to the map. Event listeners attached to this camera are notified when the pan completes.
      Specified by:
      pan in interface ICamera
      Parameters:
      x - the new X position for the camera once the panning is complete
      y - the new Y position for the camera once the panning is complete
      duration - the number of frames between this call and when the pan completes
    • clampToMap

      protected java.awt.geom.Point2D clampToMap​(java.awt.geom.Point2D focus)
    • panTime

      protected int panTime()
    • getViewportWidth

      protected double getViewportWidth()
    • getViewportHeight

      protected double getViewportHeight()