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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
changeX
(double x) Changes x by a certain amountvoid
changeY
(double y) Changes y by a certain amountvoid
changeZoom
(double dz) Changes the zoom level by a certain amountReturns the position of the spritedouble
getX()
Returns the x coordinate of the spritedouble
getY()
Returns the y coordinate of the spritedouble
getZoom()
Returns the zoom levelvoid
Resets the zoom level to 100void
setPosition
(double x, double y) Sets the position of the spritevoid
Sets the position of the sprite based on the coordinates of a given vector.void
setX
(double x) Sets the x coordinatevoid
setY
(double y) Sets the y coordinatevoid
setZoom
(double zoom) Sets the zoomvoid
setZoomLimit
(double low, double high) Sets the zoom limitsConverts local camera coordinates to screen coordinatesdouble
toGlobalX
(double x) Converts local camera x coordinate to screen x coordinatedouble
toGlobalY
(double y) Converts local camera y coordinate to screen y coordinateConverts screen coordinates to local camera coordinatesdouble
toLocalX
(double x) Converts screen x coordinate to local camera x coordinatedouble
toLocalY
(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
Returns the position of the sprite- Returns:
- a vector
-
toLocalPosition
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
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 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
-