Class Camera
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 Constructor Description Camera()
Instantiates a newCamera
instance.Method Summary
Modifier and Type Method Description protected java.awt.geom.Point2D
clampToMap(java.awt.geom.Point2D focus)
Align
getClampAlign()
Valign
getClampValign()
java.awt.geom.Point2D
getFocus()
Gets the map location that is focused by this camera.java.awt.geom.Point2D
getMapLocation(java.awt.geom.Point2D viewPortLocation)
Converts a point in screen coordinates into a map location.double
getPixelOffsetX()
Gets the x coordinate of the viewport's origin.double
getPixelOffsetY()
Gets the y coordinate of the viewport's origin.java.awt.geom.Rectangle2D
getViewport()
Gets the camera's viewport region, in screen coordinates.java.awt.geom.Point2D
getViewportDimensionCenter(IEntity entity)
Gets the center of the entity, in screen coordinates.protected double
getViewportHeight()
java.awt.geom.Point2D
getViewportLocation(double x, double y)
Converts a location in map coordinates into screen coordinates.protected double
getViewportWidth()
float
getZoom()
The zoom factor of this camera.boolean
isClampToMap()
Returns whether this camera will clamp the viewport to the bounds of the map.void
onFocus(ICamera.FocusChangedListener listener)
Adds the specified focus changed listener to receive events when the focus of this camera changed.void
onZoom(ICamera.ZoomChangedListener listener)
Adds the specified zoom changed listener to receive events when the zoom of this camera changed.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.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.protected int
panTime()
void
removeFocusListener(ICamera.FocusChangedListener listener)
Removes the specified focus changed listener.void
removeZoomListener(ICamera.ZoomChangedListener listener)
Removes the specified zoom changed listener.void
setClampAlign(Align align, Valign valign)
void
setClampToMap(boolean clampToMap)
Set the camera to clamp the viewport to the bounds of the map.void
setFocus(double x, double y)
Focuses the camera on a given point.void
setFocus(java.awt.geom.Point2D focus)
Focuses the camera on a given point.void
setZoom(float targetZoom, int delay)
Changes the camera's zoom over the specified duration (in frames) to the target zoom.void
shake(double intensity, int delay, int shakeDuration)
Shake the camera for the specified duration (in frames).void
update()
This method is called by the game loop on all objects that are attached to the loop.void
updateFocus()
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 newCamera
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.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 interfaceICamera
- 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 interfaceICamera
- 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 interfaceICamera
- 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 interfaceICamera
- Returns:
- the viewport region, in screen coordinates
getViewportDimensionCenter
Description copied from interface:ICamera
Gets the center of the entity, in screen coordinates.- Specified by:
getViewportDimensionCenter
in interfaceICamera
- 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 interfaceICamera
- 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.onZoom
Description copied from interface:ICamera
Adds the specified zoom changed listener to receive events when the zoom of this camera changed.removeZoomListener
Description copied from interface:ICamera
Removes the specified zoom changed listener.- Specified by:
removeZoomListener
in interfaceICamera
- Parameters:
listener
- The listener to add.
onFocus
Description copied from interface:ICamera
Adds the specified focus changed listener to receive events when the focus of this camera changed.removeFocusListener
Description copied from interface:ICamera
Removes the specified focus changed listener.- Specified by:
removeFocusListener
in interfaceICamera
- 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.setFocus
public void setFocus(double x, double y)Description copied from interface:ICamera
Focuses the camera on a given point.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.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.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 theClientConfiguration
.- Specified by:
update
in interfaceIUpdateable
- 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 interfaceICamera
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 interfaceICamera
- 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 interfaceICamera
- Parameters:
clampToMap
- A flag indicating whether the camera viewport should be clamped to the map boundaries.
setClampAlign
- Specified by:
setClampAlign
in interfaceICamera
getClampAlign
- Specified by:
getClampAlign
in interfaceICamera
getClampValign
- Specified by:
getClampValign
in interfaceICamera
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.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.clampToMap
protected java.awt.geom.Point2D clampToMap(java.awt.geom.Point2D focus)panTime
protected int panTime()getViewportWidth
protected double getViewportWidth()getViewportHeight
protected double getViewportHeight()