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
    double
     
    double
     
    int
     
    int
     
    boolean
    isVisible(int worldX, int worldY)
    Checks if a point is visible in the viewport
    boolean
    isVisible(int worldX, int worldY, int width, int height)
    Checks if a rectangular area is visible in the viewport
    screenToWorld(int screenX, int screenY)
    Converts screen coordinates to world coordinates
    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
    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

    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
    • 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)
    • 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
      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
      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
      Parameters:
      worldX - World X coordinate
      worldY - 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 coordinate
      worldY - World Y coordinate
      width - Width of area
      height - 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)