Class Camera

java.lang.Object
ActiverseEngine.Camera

public class Camera extends Object
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
    Constructor
    Description
    Camera(int viewWidth, int viewHeight)
    Creates a camera with specified viewport size
    Camera(int viewWidth, int viewHeight, float smoothness)
    Creates a camera with smoothing
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applySmoothZoom(double factor)
    Apply a per-frame zoom factor for smooth continuous zoom while key is held.
    double
     
    double
     
    int
     
    int
     
    double
     
    boolean
    isVisible(int worldX, int worldY)
    Checks if a point is visible in the viewport (accounts for zoom).
    boolean
    isVisible(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).
    void
    setClampToWorldBounds(boolean clamp)
    Enables or disables clamping the view to setWorldBounds(int, int).
    void
    setSmoothness(float smoothness)
     
    void
    setTarget(Actor target)
    Sets the target actor for the camera to follow
    void
    setWorldBounds(int worldWidth, int worldHeight)
    Sets the world bounds for camera clamping
    void
    setZoom(double zoom)
    Sets zoom level (clamped between ZOOM_MIN and ZOOM_MAX).
    void
    snapTo(double x, double y)
    Instantly moves camera to position
    void
    Updates the camera position (call each frame).
    worldToScreen(int worldX, int worldY)
    Converts world coordinates to screen coordinates (accounts for zoom).
    void
    Zoom in by a scaled factor (multiplicative / logarithmic feel).
    void
    Zoom out by a scaled factor (multiplicative / logarithmic feel).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Camera

      public Camera(int viewWidth, int viewHeight)
      Creates a camera with specified viewport size
      Parameters:
      viewWidth - Width of the viewport in pixels
      viewHeight - 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 viewport
      viewHeight - Height of the viewport
      smoothness - 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 world
      worldHeight - Height of the world
    • setClampToWorldBounds

      public void setClampToWorldBounds(boolean clamp)
      Enables or disables clamping the view to setWorldBounds(int, int). Use false for effectively infinite worlds.
    • setTarget

      public void setTarget(Actor target)
      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 position
      y - Y position
    • worldToScreen

      public Point worldToScreen(int worldX, int worldY)
      Converts world coordinates to screen coordinates (accounts for zoom).
      Parameters:
      worldX - World X coordinate
      worldY - World Y coordinate
      Returns:
      Screen coordinates
    • screenToWorld

      public Point screenToWorld(int screenX, int screenY)
      Converts screen coordinates to world coordinates (accounts for zoom).
      Parameters:
      screenX - Screen X coordinate
      screenY - 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)