public class CameraGame extends java.lang.Object implements Localizable
Localizable
. Also, a view can be set to avoid useless rendering when
objects are outside of the camera view.Constructor and Description |
---|
CameraGame()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
follow(Localizable localizable)
Follow automatically the specified localizable.
|
int |
getHeight()
Get the height.
|
int |
getLocationIntX()
Get the current rounded horizontal location.
|
int |
getLocationIntY()
Get the current rounded vertical location.
|
int |
getLocationOffsetX()
Get the horizontal offset location.
|
int |
getLocationOffsetY()
Get the vertical offset location.
|
double |
getLocationOldX()
Get the old horizontal location.
|
double |
getLocationOldY()
Get the old vertical location.
|
double |
getLocationRealX()
Get real horizontal location (relative location + offset location).
|
double |
getLocationRealY()
Get real vertical location (relative location + offset location).
|
double |
getLocationX()
Get the current horizontal location.
|
double |
getLocationY()
Get the current vertical location.
|
double |
getMovementHorizontal()
Get the horizontal movement (current position - old).
|
double |
getMovementVertical()
Get the vertical movement (current position - old).
|
int |
getViewHeight()
Get view height.
|
int |
getViewpointX(int x)
Get the horizontal viewpoint from the object location.
|
int |
getViewpointY(int y)
Get the vertical viewpoint from the object location.
|
int |
getViewWidth()
Get view width.
|
int |
getViewX()
Get horizontal view offset.
|
int |
getViewY()
Get vertical view offset.
|
int |
getWidth()
Get the width.
|
boolean |
isVisible(Localizable localizable)
Check if the localizable is inside the camera view.
|
boolean |
isVisible(Localizable localizable,
int radiusX,
int radiusY)
Check if the localizable is inside the camera view.
|
void |
moveLocation(double extrp,
double vx,
double vy)
Move location using a simple force.
|
void |
moveLocation(double extrp,
Force force,
Force... forces)
Move location using different forces.
|
void |
resetInterval(Localizable localizable)
Reset the camera interval to 0 by adapting its position.
|
void |
setIntervals(int intervalHorizontal,
int intervalVertical)
This represents the real position, between -interval and +interval.
|
void |
setLocation(double x,
double y)
Set location instantly.
|
void |
setLocationOffset(double x,
double y)
Set location offset.
|
void |
setLocationX(double x)
Set horizontal location.
|
void |
setLocationY(double y)
Set vertical location.
|
void |
setSize(int width,
int height)
Set size.
|
void |
setView(int x,
int y,
int width,
int height)
Define the rendering area.
|
void |
teleport(double x,
double y)
Teleport to a new location.
|
void |
teleportX(double x)
Teleport to a new horizontal location.
|
void |
teleportY(double y)
Teleport to a new vertical location.
|
public void follow(Localizable localizable)
localizable
- The localizable to follow.public void resetInterval(Localizable localizable)
localizable
- The localizable to center to.public void setIntervals(int intervalHorizontal, int intervalVertical)
For example: if the camera is following an entity and the camera horizontal interval is 16, anything that is rendered using the camera view point will see its horizontal axis change when the entity horizontal location will be before / after the camera location -16 / +16:
<--camera movement--> -16[..no camera movement..]+16 <--camera movement-->
intervalHorizontal
- The horizontal margin.intervalVertical
- The vertical margin.public void setView(int x, int y, int width, int height)
For example:
(0, 0, 320, 240)
, and the map tile size is 16
, then
20
horizontal tiles and 15
vertical tiles will be rendered from 0, 0
(screen top-left).(64, 64, 240, 160)
, and the map tile size is 16
, then
15
horizontal tiles and 10
vertical tiles will be rendered from 64, 64
(screen top-left).
It is also compatible with entity rendering (by using an HandlerEntityGame
). The entity which are outside
the camera view will not be rendered. This avoid useless rendering.
Note: The rendering view is from the camera location. So x
and y
are an offset from
this location.
x
- The horizontal offset.y
- The vertical offset.width
- The rendering width (positive value).height
- The rendering height (positive value).public int getViewpointX(int x)
x
- The object horizontal location.public int getViewpointY(int y)
y
- The object vertical location.public int getViewX()
public int getViewY()
public int getViewWidth()
public int getViewHeight()
public double getMovementHorizontal()
public double getMovementVertical()
public double getLocationRealX()
public double getLocationRealY()
public boolean isVisible(Localizable localizable)
localizable
- The localizable to check.true
if visible, false
else.public boolean isVisible(Localizable localizable, int radiusX, int radiusY)
localizable
- The localizable to check.radiusX
- The radius offset x.radiusY
- The radius offset y.true
if visible, false
else.public void teleport(double x, double y)
Localizable
teleport
in interface Localizable
x
- The new horizontal location.y
- The new vertical location.public void teleportX(double x)
Localizable
teleportX
in interface Localizable
x
- The new horizontal location.public void teleportY(double y)
Localizable
teleportY
in interface Localizable
y
- The new vertical location.public void moveLocation(double extrp, Force force, Force... forces)
Localizable
moveLocation
in interface Localizable
extrp
- The extrapolation value.force
- The primary force.forces
- The other forces.public void moveLocation(double extrp, double vx, double vy)
Localizable
moveLocation
in interface Localizable
extrp
- The extrapolation value.vx
- The horizontal force.vy
- The vertical force.public void setLocation(double x, double y)
Localizable
setLocation
in interface Localizable
x
- The new horizontal location.y
- The new vertical location.public void setLocationX(double x)
Localizable
setLocationX
in interface Localizable
x
- The new horizontal location.public void setLocationY(double y)
Localizable
setLocationY
in interface Localizable
y
- The new vertical location.public void setLocationOffset(double x, double y)
Localizable
setLocationOffset
in interface Localizable
x
- The new horizontal location offset.y
- The new vertical location offset.public void setSize(int width, int height)
Localizable
setSize
in interface Localizable
width
- The width.height
- The height.public int getLocationIntX()
Surface
getLocationIntX
in interface Surface
public int getLocationIntY()
Surface
getLocationIntY
in interface Surface
public double getLocationX()
Localizable
getLocationX
in interface Localizable
public double getLocationY()
Localizable
getLocationY
in interface Localizable
public double getLocationOldX()
Localizable
getLocationOldX
in interface Localizable
public double getLocationOldY()
Localizable
getLocationOldY
in interface Localizable
public int getLocationOffsetX()
Surface
getLocationOffsetX
in interface Surface
public int getLocationOffsetY()
Surface
getLocationOffsetY
in interface Surface
public int getWidth()
Surface