Interface ICamera

All Superinterfaces:
IUpdateable
All Known Implementing Classes:
Camera, FreeFlightCamera, PositionLockCamera

public interface ICamera
extends IUpdateable
The Interface ICamera defines methods that allow to determine where entities or tiles are rendered on the current screen. Camera control is based on a Focus system. Generally, the camera will always try to keep the focus point in the center of the viewport. There are two coordinate systems referenced in ICamera methods: map coordinates, and screen coordinates. The camera is responsible for converting between the two coordinate systems.
  • Nested Class Summary

    Nested Classes 
    Modifier and TypeInterfaceDescription
    static interface ICamera.FocusChangedListener
    This listener interface receives focus events for a camera.
    static interface ICamera.ZoomChangedListener
    This listener interface receives zoom events for a camera.
  • Method Summary

    Modifier and TypeMethodDescription
    AligngetClampAlign() 
    ValigngetClampValign() 
    java.awt.geom.Point2DgetFocus()
    Gets the map location that is focused by this camera.
    java.awt.geom.Point2DgetMapLocation​(java.awt.geom.Point2D point)
    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.
    default floatgetRenderScale()
    Combines this camera's zoom with the game's render scale.
    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.
    java.awt.geom.Point2DgetViewportLocation​(double x, double y)
    Converts a location in map coordinates into screen coordinates.
    default java.awt.geom.Point2DgetViewportLocation​(IEntity entity)
    Converts the entity's location into screen coordinates.
    default java.awt.geom.Point2DgetViewportLocation​(java.awt.geom.Point2D point)
    Converts a location in map coordinates into screen coordinates.
    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.
    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.
    default voidsetFocus​(java.awt.geom.Point2D focus)
    Focuses the camera on a given point.
    voidsetZoom​(float zoom, int duration)
    Changes the camera's zoom over the specified duration (in frames) to the target zoom.
    voidshake​(double intensity, int delay, int duration)
    Shake the camera for the specified duration (in frames).
    voidupdateFocus()
    Currently an update function for the shake effect.

    Methods inherited from interface de.gurkenlabs.litiengine.IUpdateable

    update
  • Method Details

    • onZoom

      void onZoom​(ICamera.ZoomChangedListener listener)
      Adds the specified zoom changed listener to receive events when the zoom of this camera changed.
      Parameters:
      listener - The listener to add.
    • removeZoomListener

      void removeZoomListener​(ICamera.ZoomChangedListener listener)
      Removes the specified zoom changed listener.
      Parameters:
      listener - The listener to add.
    • onFocus

      void onFocus​(ICamera.FocusChangedListener listener)
      Adds the specified focus changed listener to receive events when the focus of this camera changed.
      Parameters:
      listener - The listener to add.
    • removeFocusListener

      void removeFocusListener​(ICamera.FocusChangedListener listener)
      Removes the specified focus changed listener.
      Parameters:
      listener - The listener to add.
    • getFocus

      java.awt.geom.Point2D getFocus()
      Gets the map location that is focused by this camera.
      Returns:
      the focus's location in map coordinates
    • getMapLocation

      java.awt.geom.Point2D getMapLocation​(java.awt.geom.Point2D point)
      Converts a point in screen coordinates into a map location.
      Parameters:
      point - the point in screen coordinates
      Returns:
      the map location
    • getPixelOffsetX

      double getPixelOffsetX()
      Gets the x coordinate of the viewport's origin.
      Returns:
      the offset, in screen coordinates
    • getPixelOffsetY

      double getPixelOffsetY()
      Gets the y coordinate of the viewport's origin.
      Returns:
      the offset, in screen coordinates
    • getViewport

      java.awt.geom.Rectangle2D getViewport()
      Gets the camera's viewport region, in screen coordinates.
      Returns:
      the viewport region, in screen coordinates
    • getViewportDimensionCenter

      java.awt.geom.Point2D getViewportDimensionCenter​(IEntity entity)
      Gets the center of the entity, in screen coordinates.
      Parameters:
      entity - The entity to retrieve the dimension center for.
      Returns:
      the center, in screen coordinates
    • getViewportLocation

      java.awt.geom.Point2D getViewportLocation​(double x, double y)
      Converts a location in map coordinates into screen coordinates.
      Parameters:
      x - The x-coordinate of the viewport location.
      y - The y-coordinate of the viewport location.
      Returns:
      the screen location
    • getViewportLocation

      default java.awt.geom.Point2D getViewportLocation​(IEntity entity)
      Converts the entity's location into screen coordinates.
      Parameters:
      entity - the entity
      Returns:
      the screen location
    • getViewportLocation

      default java.awt.geom.Point2D getViewportLocation​(java.awt.geom.Point2D point)
      Converts a location in map coordinates into screen coordinates.
      Parameters:
      point - the point
      Returns:
      the screen location
    • getRenderScale

      default float getRenderScale()
      Combines this camera's zoom with the game's render scale.
      Returns:
      the scale factor
      See Also:
      RenderEngine.setBaseRenderScale(float)
    • getZoom

      float getZoom()
      The zoom factor of this camera.
      Returns:
      the scale factor
    • setFocus

      default void setFocus​(java.awt.geom.Point2D focus)
      Focuses the camera on a given point.
      Parameters:
      focus - the point, in map coordinates
    • setFocus

      void setFocus​(double x, double y)
      Focuses the camera on a given point.
      Parameters:
      x - the x coordinate of the point, in map coordinates
      y - the y coordinate of the point, in map coordinates
    • pan

      void pan​(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. Event listeners attached to this camera are notified when the pan completes.
      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

      void pan​(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. Event listeners attached to this camera are notified when the pan completes.
      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
    • setZoom

      void setZoom​(float zoom, int duration)
      Changes the camera's zoom over the specified duration (in frames) to the target zoom.
      Parameters:
      zoom - the new zoom scale
      duration - the number of frames between this call and when the zoom completes
    • isClampToMap

      boolean isClampToMap()
      Returns whether this camera will clamp the viewport to the bounds of the map.
      Returns:
      True if the camera viewport is currently clamped to the map boundaries; otherwise false.
    • setClampToMap

      void setClampToMap​(boolean clampToMap)
      Set the camera to clamp the viewport to the bounds of the map.
      Parameters:
      clampToMap - A flag indicating whether the camera viewport should be clamped to the map boundaries.
    • setClampAlign

      void setClampAlign​(Align align, Valign valign)
    • getClampAlign

      Align getClampAlign()
    • getClampValign

      Valign getClampValign()
    • shake

      void shake​(double intensity, int delay, int duration)
      Shake the camera for the specified duration (in frames). The way the camera shakes is implementation defined.
      Parameters:
      intensity - The intensity of the screen shake effect.
      delay - The delay before the effect starts.
      duration - The duration of the effect.
    • updateFocus

      void updateFocus()
      Currently an update function for the shake effect.