Class Camera
java.lang.Object
org.openpatch.scratch.Camera
The camera of a stage: which part of the world the stage shows. Every layer but
Layer.UI follows it, the backdrop included; pens draw where the camera shows their
position when they draw. Unused, it shows the world as it is: position (0, 0), zoom 100.
Camera camera = this.getStage().getCamera();
camera.setPosition(player.getX(), player.getY());
World coordinates are where sprites are; screen coordinates are where something shows on
the stage, with (0, 0) in its centre. The mouse is reported in world coordinates by
getMouseX(), so it can be compared with sprite positions directly.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeX(double dx) voidchangeY(double dy) voidchangeZoom(double dz) doublegetX()doublegetY()doublegetZoom()voidBack to zoom 100.voidsetPosition(double x, double y) Centres the camera on a world position.voidsetPosition(Vector2 position) Centres the camera on a world position.voidsetX(double x) voidsetY(double y) voidsetZoom(double zoom) Sets the zoom in percent: 200 shows everything twice as large, 50 half as large.voidsetZoomLimit(double min, double max) Limits the zoom.toScreenPosition(Vector2 world) Where a world position shows on the stage.doubletoScreenX(double worldX) doubletoScreenY(double worldY) toWorldPosition(Vector2 screen) Which world position shows at a place on the stage.doubletoWorldX(double screenX) doubletoWorldY(double screenY)
-
Constructor Details
-
Camera
public Camera()A camera at (0, 0) with zoom 100. Every stage has its own:getStage().getCamera().
-
-
Method Details
-
setPosition
public void setPosition(double x, double y) Centres the camera on a world position.- Parameters:
x- world xy- world y
-
setPosition
Centres the camera on a world position.- Parameters:
position- world position
-
getPosition
- Returns:
- the world position at the stage's centre
-
getX
public double getX()- Returns:
- the world x at the stage's centre
-
setX
public void setX(double x) - Parameters:
x- the world x to show at the stage's centre
-
changeX
public void changeX(double dx) - Parameters:
dx- how far to move the camera along x
-
getY
public double getY()- Returns:
- the world y at the stage's centre
-
setY
public void setY(double y) - Parameters:
y- the world y to show at the stage's centre
-
changeY
public void changeY(double dy) - Parameters:
dy- how far to move the camera along y
-
setZoom
public void setZoom(double zoom) Sets the zoom in percent: 200 shows everything twice as large, 50 half as large. It stays within the zoom limits (50 to 200 unless changed).- Parameters:
zoom- the zoom in percent
-
changeZoom
public void changeZoom(double dz) - Parameters:
dz- percentage points to add to the zoom
-
getZoom
public double getZoom()- Returns:
- the zoom in percent
-
resetZoom
public void resetZoom()Back to zoom 100. -
setZoomLimit
public void setZoomLimit(double min, double max) Limits the zoom.- Parameters:
min- the smallest zoom in percentmax- the largest zoom in percent
-
toScreenPosition
-
toScreenX
public double toScreenX(double worldX) - Parameters:
worldX- a world x- Returns:
- where it shows on the stage
-
toScreenY
public double toScreenY(double worldY) - Parameters:
worldY- a world y- Returns:
- where it shows on the stage
-
toWorldPosition
-
toWorldX
public double toWorldX(double screenX) - Parameters:
screenX- an x on the stage- Returns:
- the world x shown there
-
toWorldY
public double toWorldY(double screenY) - Parameters:
screenY- a y on the stage- Returns:
- the world y shown there
-