Class Camera
- All Implemented Interfaces:
ICamera, IUpdateable, Tweenable
- Direct Known Subclasses:
FreeFlightCamera, LocationLockCamera
-
Nested Class Summary
Nested classes/interfaces inherited from interface ICamera
ICamera.FocusChangedListener, ICamera.ZoomChangedListener -
Field Summary
Fields inherited from interface IUpdateable
DEFAULT_UPDATE_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Point2DclampToMap(Point2D focus) Clamps a given focus point to ensure it remains within the visible bounds of the current map.Gets the current horizontal alignment used for clamping the camera to the map boundaries.Gets the current vertical alignment used for clamping the camera to the map boundaries.getFocus()Gets the map location that is focused by this camera.getMapLocation(Point2D viewPortLocation) Converts a point in screen coordinates into a map location.doubleGets the x coordinate of the viewport's origin.doubleGets the y coordinate of the viewport's origin.float[]getTweenValues(TweenType tweenType) Provides current tween values for camera-relatedTweenTypes so that the camera can be animated by theTweenEngine.Gets the camera's viewport region, in screen coordinates.getViewportDimensionCenter(IEntity entity) Gets the center of the entity, in screen coordinates.protected doubleCalculates the height of the camera's viewport in world units.getViewportLocation(double x, double y) Converts a location in map coordinates into screen coordinates.protected doubleCalculates the width of the camera's viewport in world units.floatgetZoom()The zoom factor of this camera.booleanReturns 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.voidPans the camera over the specified duration (in frames) to the target location, after accounting for modifications such as clamping to the map.protected intpanTime()Gets the remaining pan time for the camera.voidRemoves the specified focus changed listener.voidRemoves the specified zoom changed listener.voidsetClampAlign(Align align, Valign valign) Sets the alignment for clamping the camera to the map boundaries.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.voidFocuses the camera on a given point.voidsetTweenValues(TweenType tweenType, float[] newValues) Applies interpolated tween values to the camera.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) Shakes the camera for the specified duration.voidupdate()This method is called by the game loop on all objects that are attached to the loop.voidCurrently an update function for the shake effect.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ICamera
getRenderScale, getViewportLocation, getViewportLocationMethods inherited from interface IUpdateable
getUpdatePriority
-
Constructor Details
-
Camera
public Camera()Instantiates a newCamerainstance.
-
-
Method Details
-
getFocus
-
getMapLocation
Description copied from interface:ICameraConverts a point in screen coordinates into a map location.- Specified by:
getMapLocationin interfaceICamera- Parameters:
viewPortLocation- the point in screen coordinates- Returns:
- the map location
-
getPixelOffsetX
public double getPixelOffsetX()Description copied from interface:ICameraGets the x coordinate of the viewport's origin.- Specified by:
getPixelOffsetXin interfaceICamera- Returns:
- the offset, in screen coordinates
-
getPixelOffsetY
public double getPixelOffsetY()Description copied from interface:ICameraGets the y coordinate of the viewport's origin.- Specified by:
getPixelOffsetYin interfaceICamera- Returns:
- the offset, in screen coordinates
-
getViewport
Description copied from interface:ICameraGets the camera's viewport region, in screen coordinates.- Specified by:
getViewportin interfaceICamera- Returns:
- the viewport region, in screen coordinates
-
getViewportDimensionCenter
Description copied from interface:ICameraGets the center of the entity, in screen coordinates.- Specified by:
getViewportDimensionCenterin interfaceICamera- Parameters:
entity- The entity to retrieve the dimension center for.- Returns:
- the center, in screen coordinates
-
getViewportLocation
Description copied from interface:ICameraConverts a location in map coordinates into screen coordinates.- Specified by:
getViewportLocationin interfaceICamera- Parameters:
x- The x-coordinate of the viewport location.y- The y-coordinate of the viewport location.- Returns:
- the screen location
-
getZoom
-
onZoom
Description copied from interface:ICameraAdds the specified zoom changed listener to receive events when the zoom of this camera changed. -
removeZoomListener
Description copied from interface:ICameraRemoves the specified zoom changed listener.- Specified by:
removeZoomListenerin interfaceICamera- Parameters:
listener- The listener to remove.
-
onFocus
Description copied from interface:ICameraAdds the specified focus changed listener to receive events when the focus of this camera changed. -
removeFocusListener
Description copied from interface:ICameraRemoves the specified focus changed listener.- Specified by:
removeFocusListenerin interfaceICamera- Parameters:
listener- The listener to remove.
-
setFocus
-
setFocus
-
setZoom
public void setZoom(float targetZoom, int delay) Description copied from interface:ICameraChanges 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:ICameraShakes the camera for the specified duration. The way the camera shakes is implementation defined. -
update
public void update()Description copied from interface:IUpdateableThis 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:
updatein interfaceIUpdateable- See Also:
-
updateFocus
public void updateFocus()Description copied from interface:ICameraCurrently an update function for the shake effect.- Specified by:
updateFocusin interfaceICamera
-
isClampToMap
public boolean isClampToMap()Description copied from interface:ICameraReturns whether this camera will clamp the viewport to the bounds of the map.- Specified by:
isClampToMapin 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:ICameraSet the camera to clamp the viewport to the bounds of the map.- Specified by:
setClampToMapin interfaceICamera- Parameters:
clampToMap- A flag indicating whether the camera viewport should be clamped to the map boundaries.
-
setClampAlign
Description copied from interface:ICameraSets the alignment for clamping the camera to the map boundaries.- Specified by:
setClampAlignin interfaceICamera- Parameters:
align- The horizontal alignment (e.g., left, center, or right).valign- The vertical alignment (e.g., top, middle, or bottom).
-
getClampAlign
Description copied from interface:ICameraGets the current horizontal alignment used for clamping the camera to the map boundaries.- Specified by:
getClampAlignin interfaceICamera- Returns:
- The horizontal alignment.
-
getClampValign
Description copied from interface:ICameraGets the current vertical alignment used for clamping the camera to the map boundaries.- Specified by:
getClampValignin interfaceICamera- Returns:
- The vertical alignment.
-
pan
Description copied from interface:ICameraPans 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:ICameraPans 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
Clamps a given focus point to ensure it remains within the visible bounds of the current map.
This method ensures that the camera's focus point does not move outside the boundaries of the map. It centers the camera around the focus point, but only to the extent that the map dimensions allow. If the viewport is larger than the map in either dimension, the Camera's Align and VAlign is applied to determine how to handle the excess space.
- Parameters:
focus- the desired focus point in map coordinates.- Returns:
- a new
Point2Drepresenting the clamped focus point, adjusted to remain within the bounds of the map view.
-
panTime
protected int panTime()Gets the remaining pan time for the camera.- Returns:
- The remaining time (in ticks) for the camera to complete its pan operation.
-
getViewportWidth
protected double getViewportWidth()Calculates the width of the camera's viewport in world units.
The viewport width is determined by dividing the game window's resolution width by the current render scale.
- Returns:
- The width of the viewport in world units.
-
getViewportHeight
protected double getViewportHeight()Calculates the height of the camera's viewport in world units.
The viewport height is determined by dividing the game window's resolution height by the current render scale.
- Returns:
- The height of the viewport in world units.
-
getTweenValues
Provides current tween values for camera-relatedTweenTypes so that the camera can be animated by theTweenEngine. SupportsTweenType.ZOOM,TweenType.LOCATION_X,TweenType.LOCATION_YandTweenType.LOCATION_XYfor zooming and panning.- Specified by:
getTweenValuesin interfaceTweenable- Parameters:
tweenType- The tween type of this interpolation, determining which values are modified.- Returns:
- The array of current tween values.
-
setTweenValues
Applies interpolated tween values to the camera. SeegetTweenValues(TweenType)for the list of supported tween types.- Specified by:
setTweenValuesin interfaceTweenable- Parameters:
tweenType- The tween type of this interpolation, determining which values are modified.newValues- The new values determined by the tween equation.
-