Class Camera
java.lang.Object
ActiverseEngine.Camera
Camera - Viewport management system for following actors and scrolling worlds
Essential for infinite world generation and smooth camera movement
- Version:
- 1.4.1
- Author:
- Knivier
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplySmoothZoom(double factor) Apply a per-frame zoom factor for smooth continuous zoom while key is held.doubledoubleintintdoublegetZoom()booleanisVisible(int worldX, int worldY) Checks if a point is visible in the viewport (accounts for zoom).booleanisVisible(int worldX, int worldY, int width, int height) Checks if a rectangular area is visible in the viewport (accounts for zoom).screenToWorld(int screenX, int screenY) Converts screen coordinates to world coordinates (accounts for zoom).voidsetClampToWorldBounds(boolean clamp) Enables or disables clamping the view tosetWorldBounds(int, int).voidsetSmoothness(float smoothness) voidSets the target actor for the camera to followvoidsetWorldBounds(int worldWidth, int worldHeight) Sets the world bounds for camera clampingvoidsetZoom(double zoom) Sets zoom level (clamped between ZOOM_MIN and ZOOM_MAX).voidsnapTo(double x, double y) Instantly moves camera to positionvoidupdate()Updates the camera position (call each frame).worldToScreen(int worldX, int worldY) Converts world coordinates to screen coordinates (accounts for zoom).voidzoomIn()Zoom in by a scaled factor (multiplicative / logarithmic feel).voidzoomOut()Zoom out by a scaled factor (multiplicative / logarithmic feel).
-
Constructor Details
-
Camera
public Camera(int viewWidth, int viewHeight) Creates a camera with specified viewport size- Parameters:
viewWidth- Width of the viewport in pixelsviewHeight- Height of the viewport in pixels
-
Camera
public Camera(int viewWidth, int viewHeight, float smoothness) Creates a camera with smoothing- Parameters:
viewWidth- Width of the viewportviewHeight- Height of the viewportsmoothness- Smoothness factor (0.0 to 1.0)
-
-
Method Details
-
setWorldBounds
public void setWorldBounds(int worldWidth, int worldHeight) Sets the world bounds for camera clamping- Parameters:
worldWidth- Width of the worldworldHeight- Height of the world
-
setClampToWorldBounds
public void setClampToWorldBounds(boolean clamp) Enables or disables clamping the view tosetWorldBounds(int, int). Usefalsefor effectively infinite worlds. -
setTarget
Sets the target actor for the camera to follow- Parameters:
target- The actor to follow
-
update
public void update()Updates the camera position (call each frame). Keeps the target centered; when target is null, offset does not change. -
snapTo
public void snapTo(double x, double y) Instantly moves camera to position- Parameters:
x- X positiony- Y position
-
worldToScreen
Converts world coordinates to screen coordinates (accounts for zoom).- Parameters:
worldX- World X coordinateworldY- World Y coordinate- Returns:
- Screen coordinates
-
screenToWorld
Converts screen coordinates to world coordinates (accounts for zoom).- Parameters:
screenX- Screen X coordinatescreenY- Screen Y coordinate- Returns:
- World coordinates
-
isVisible
public boolean isVisible(int worldX, int worldY) Checks if a point is visible in the viewport (accounts for zoom). -
isVisible
public boolean isVisible(int worldX, int worldY, int width, int height) Checks if a rectangular area is visible in the viewport (accounts for zoom). -
getOffsetX
public double getOffsetX() -
getOffsetY
public double getOffsetY() -
getViewWidth
public int getViewWidth() -
getViewHeight
public int getViewHeight() -
getZoom
public double getZoom() -
setZoom
public void setZoom(double zoom) Sets zoom level (clamped between ZOOM_MIN and ZOOM_MAX).- Parameters:
zoom- Scale factor; 1.0 = default, >1 = zoom in, <1 = zoom out
-
zoomIn
public void zoomIn()Zoom in by a scaled factor (multiplicative / logarithmic feel). -
zoomOut
public void zoomOut()Zoom out by a scaled factor (multiplicative / logarithmic feel). -
applySmoothZoom
public void applySmoothZoom(double factor) Apply a per-frame zoom factor for smooth continuous zoom while key is held. Call every frame: factor > 1 to zoom in, factor < 1 to zoom out. e.g. applySmoothZoom(1.012) when T held, applySmoothZoom(0.988) when G held -
setSmoothness
public void setSmoothness(float smoothness)
-