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 TypeMethodDescriptiondoubledoubleintintbooleanisVisible(int worldX, int worldY) Checks if a point is visible in the viewportbooleanisVisible(int worldX, int worldY, int width, int height) Checks if a rectangular area is visible in the viewportscreenToWorld(int screenX, int screenY) Converts screen coordinates to world coordinatesvoidsetSmoothness(float smoothness) voidSets the target actor for the camera to followvoidsetWorldBounds(int worldWidth, int worldHeight) Sets the world bounds for camera clampingvoidsnapTo(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
-
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
-
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) -
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- Parameters:
worldX- World X coordinateworldY- World Y coordinate- Returns:
- Screen coordinates
-
screenToWorld
Converts screen coordinates to world coordinates- 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- Parameters:
worldX- World X coordinateworldY- World Y coordinate- Returns:
- true if point is visible
-
isVisible
public boolean isVisible(int worldX, int worldY, int width, int height) Checks if a rectangular area is visible in the viewport- Parameters:
worldX- World X coordinateworldY- World Y coordinatewidth- Width of areaheight- Height of area- Returns:
- true if area intersects viewport
-
getOffsetX
public double getOffsetX() -
getOffsetY
public double getOffsetY() -
getViewWidth
public int getViewWidth() -
getViewHeight
public int getViewHeight() -
setSmoothness
public void setSmoothness(float smoothness)
-