Class Camera
java.lang.Object
org.openpatch.scratch.extensions.camera.Camera
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeX(double x) Changes x by a certain amountvoidchangeY(double y) Changes y by a certain amountvoidchangeZoom(double dz) Changes the zoom level by a certain amountReturns the position of the spritedoublegetX()Returns the x coordinate of the spritedoublegetY()Returns the y coordinate of the spritedoublegetZoom()Returns the zoom levelvoidResets the zoom level to 100voidsetPosition(double x, double y) Sets the position of the spritevoidSets the position of the sprite based on the coordinates of a given vector.voidsetX(double x) Sets the x coordinatevoidsetY(double y) Sets the y coordinatevoidsetZoom(double zoom) Sets the zoomvoidsetZoomLimit(double low, double high) Sets the zoom limitsConverts local camera coordinates to screen coordinatesdoubletoGlobalX(double x) Converts local camera x coordinate to screen x coordinatedoubletoGlobalY(double y) Converts local camera y coordinate to screen y coordinateConverts screen coordinates to local camera coordinatesdoubletoLocalX(double x) Converts screen x coordinate to local camera x coordinatedoubletoLocalY(double y) Converts screen y coordinate to local camera y coordinate
-
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 coordinatey- a y coordinate
-
setPosition
Sets the position of the sprite based on the coordinates of a given vector.- Parameters:
v- a vector
-
getPosition
-
toLocalPosition
-
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
-
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 limithigh- 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
-