java.lang.Object
org.openpatch.scratch.extensions.camera.Camera

public class Camera extends Object
The Camera class represents a camera that can be used to view a scene. It provides methods to set the position of the camera, convert between screen and local coordinates, and zoom in and out.

Example usage:


 Camera camera = new Camera();
 camera.setPosition(0, 0);
 camera.setZoom(200);
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Camera with default values.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    changeX(double x)
    Changes x by a certain amount
    void
    changeY(double y)
    Changes y by a certain amount
    void
    changeZoom(double dz)
    Changes the zoom level by a certain amount
    Returns the position of the sprite
    double
    Returns the x coordinate of the sprite
    double
    Returns the y coordinate of the sprite
    double
    Returns the zoom level
    void
    Resets the zoom level to 100
    void
    setPosition(double x, double y)
    Sets the position of the sprite
    void
    Sets the position of the sprite based on the coordinates of a given vector.
    void
    setX(double x)
    Sets the x coordinate
    void
    setY(double y)
    Sets the y coordinate
    void
    setZoom(double zoom)
    Sets the zoom
    void
    setZoomLimit(double low, double high)
    Sets the zoom limits
    Converts local camera coordinates to screen coordinates
    double
    toGlobalX(double x)
    Converts local camera x coordinate to screen x coordinate
    double
    toGlobalY(double y)
    Converts local camera y coordinate to screen y coordinate
    Converts screen coordinates to local camera coordinates
    double
    toLocalX(double x)
    Converts screen x coordinate to local camera x coordinate
    double
    toLocalY(double y)
    Converts screen y coordinate to local camera y coordinate

    Methods inherited from class java.lang.Object

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

    • Camera

      public Camera()
      Constructs a new Camera with default values. The default position is (0, 0) and the default zoom level is 100.
  • Method Details

    • setPosition

      public void setPosition(double x, double y)
      Sets the position of the sprite
      Parameters:
      x - a x coordinate
      y - a y coordinate
    • setPosition

      public void setPosition(Vector2 v)
      Sets the position of the sprite based on the coordinates of a given vector.
      Parameters:
      v - a vector
    • getPosition

      public Vector2 getPosition()
      Returns the position of the sprite
      Returns:
      a vector
    • toLocalPosition

      public Vector2 toLocalPosition(Vector2 v)
      Converts screen coordinates to local camera coordinates
      Parameters:
      v - screen coordinates
      Returns:
      local coordinates
    • toLocalX

      public double toLocalX(double x)
      Converts screen x coordinate to local camera x coordinate
      Parameters:
      x - screen x coordinate
      Returns:
      local x coordinate
    • toLocalY

      public double toLocalY(double y)
      Converts screen y coordinate to local camera y coordinate
      Parameters:
      y - screen y coordinate
      Returns:
      local y coordinate
    • toGlobalPosition

      public Vector2 toGlobalPosition(Vector2 v)
      Converts local camera coordinates to screen coordinates
      Parameters:
      v - local camera coordinates
      Returns:
      screen coordinates
    • toGlobalX

      public double toGlobalX(double x)
      Converts local camera x coordinate to screen x coordinate
      Parameters:
      x - local camera x coordinate
      Returns:
      screen x coordinate
    • toGlobalY

      public double toGlobalY(double y)
      Converts local camera y coordinate to screen y coordinate
      Parameters:
      y - local camera y coordinate
      Returns:
      screen y coordinate
    • getX

      public double getX()
      Returns the x coordinate of the sprite
      Returns:
      a x coordinate
    • setX

      public void setX(double x)
      Sets the x coordinate
      Parameters:
      x - a x coordinate
    • changeX

      public void changeX(double x)
      Changes x by a certain amount
      Parameters:
      x - number in pixels
    • getY

      public double getY()
      Returns the y coordinate of the sprite
      Returns:
      a y coordinate
    • setY

      public void setY(double y)
      Sets the y coordinate
      Parameters:
      y - a y coordinate
    • changeY

      public void changeY(double y)
      Changes y by a certain amount
      Parameters:
      y - number in pixels
    • setZoomLimit

      public void setZoomLimit(double low, double high)
      Sets the zoom limits
      Parameters:
      low - the lower limit
      high - the upper limit
    • setZoom

      public void setZoom(double zoom)
      Sets the zoom
      Parameters:
      zoom - the zoom level
    • getZoom

      public double getZoom()
      Returns the zoom level
      Returns:
      the zoom level
    • resetZoom

      public void resetZoom()
      Resets the zoom level to 100
    • changeZoom

      public void changeZoom(double dz)
      Changes the zoom level by a certain amount
      Parameters:
      dz - the amount to change the zoom level by