T
- The type of CellGame that uses the SpaceStates that this Viewport
can be assigned topublic class Viewport<T extends CellGame> extends SpaceThinker<T>
A Viewport is a SpaceThinker that represents a rectangular region of the screen through which the space of the SpaceState to which it is assigned can be viewed. The center of a Viewport's rectangular field of view in its SpaceState is marked by a SpaceObject called the Viewport's camera. To render any visuals, including its HUD if it has one, a Viewport must be assigned to a SpaceState through its setViewport() method. To render the region of its SpaceState in its field of view, a Viewport's camera must be assigned to the same SpaceState as it.
HUDs may be assigned to one Viewport each. Only one HUD may be assigned to a given Viewport at once. A Viewport's HUD uses the region of the screen that the Viewport occupies as its rendering region.
Constructor and Description |
---|
Viewport(HUD<T> hud,
double x1,
double y1,
double x2,
double y2)
Creates a new Viewport that occupies the specified region of the screen.
|
Modifier and Type | Method and Description |
---|---|
void |
addedActions(T game,
SpaceState<T> levelState)
Actions for this Thinker to take immediately after being added to a new
CellGameState.
|
int |
getBottomEdge()
Returns the y-coordinate in pixels of this Viewport's rendering region's
actual bottom edge on the screen.
|
SpaceObject |
getCamera()
Returns this Viewport's camera, or null if it has none.
|
double |
getHeight()
Returns this Viewport's height in pixels on the screen.
|
HUD<T> |
getHUD()
Returns the HUD that is currently assigned to this Viewport, or null if
there is none.
|
int |
getLeftEdge()
Returns the x-coordinate in pixels of this Viewport's rendering region's
actual left edge on the screen.
|
int |
getRightEdge()
Returns the x-coordinate in pixels of this Viewport's rendering region's
actual right edge on the screen.
|
int |
getTopEdge()
Returns the y-coordinate in pixels of this Viewport's rendering region's
actual top edge on the screen.
|
double |
getWidth()
Returns this Viewport's width in pixels on the screen.
|
double |
getX1()
Returns the x-coordinate in pixels of this Viewport's left edge on the
screen.
|
double |
getX2()
Returns the x-coordinate in pixels of this Viewport's right edge on the
screen.
|
double |
getY1()
Returns the y-coordinate in pixels of this Viewport's top edge on the
screen.
|
double |
getY2()
Returns the y-coordinate in pixels of this Viewport's bottom edge on the
screen.
|
boolean |
rectangleIsVisible(double x1,
double y1,
double x2,
double y2)
Returns whether any part of the specified rectangular region is visible
through this Viewport.
|
void |
removedActions(T game,
SpaceState<T> levelState)
Actions for this Thinker to take immediately before being removed from
its CellGameState.
|
void |
setCamera(SpaceObject camera)
Sets this Viewport's camera to the specified SpaceObject, or to none if
the specified SpaceObject is null.
|
boolean |
setHUD(HUD<T> hud)
Sets the HUD that is assigned to this Viewport to the specified HUD, if
it is not already assigned to a SpaceState.
|
boolean |
setX1(double x1)
Sets the x-coordinate in pixels of this Viewport's left edge on the
screen to the specified value, if doing so would not cause this
Viewport's width to be negative.
|
boolean |
setX2(double x2)
Sets the x-coordinate in pixels of this Viewport's right edge on the
screen to the specified value, if doing so would not cause this
Viewport's width to be negative.
|
boolean |
setY1(double y1)
Sets the y-coordinate in pixels of this Viewport's top edge on the screen
to the specified value, if doing so would not cause this Viewport's
height to be negative.
|
boolean |
setY2(double y2)
Sets the y-coordinate in pixels of this Viewport's bottom edge on the
screen to the specified value, if doing so would not cause this
Viewport's height to be negative.
|
afterMovementActions, beforeMovementActions, getThis
frameActions, getActionPriority, getEffectiveTimeFactor, getGameState, getNewActionPriority, getNewGameState, getThinkerState, getThinkerStateDuration, getTimeFactor, getTimerValue, setActionPriority, setGameState, setThinkerState, setThinkerStateDuration, setTimeFactor, setTimerValue, timeUnitActions
public Viewport(HUD<T> hud, double x1, double y1, double x2, double y2)
hud
- This Viewport's HUD, or null if it should have nonex1
- The x-coordinate in pixels of this Viewport's left edge on the
screeny1
- The y-coordinate in pixels of this Viewport's top edge on the
screenx2
- The x-coordinate in pixels of this Viewport's right edge on the
screeny2
- The y-coordinate in pixels of this Viewport's bottom edge on
the screenpublic final void addedActions(T game, SpaceState<T> levelState)
Thinker
addedActions
in class Thinker<T extends CellGame,SpaceState<T extends CellGame>,SpaceThinker<T extends CellGame>,SpaceThinkerState<T extends CellGame>>
game
- This Thinker's CellGamelevelState
- This Thinker's CellGameStatepublic final void removedActions(T game, SpaceState<T> levelState)
Thinker
removedActions
in class Thinker<T extends CellGame,SpaceState<T extends CellGame>,SpaceThinker<T extends CellGame>,SpaceThinkerState<T extends CellGame>>
game
- This Thinker's CellGamelevelState
- This Thinker's CellGameStatepublic final SpaceObject getCamera()
public final void setCamera(SpaceObject camera)
camera
- The new camerapublic final HUD<T> getHUD()
public final boolean setHUD(HUD<T> hud)
hud
- The HUD to addpublic final double getX1()
public final double getY1()
public final double getX2()
public final double getY2()
public final boolean setX1(double x1)
x1
- The new x-coordinate in pixels of this Viewport's left edgepublic final boolean setY1(double y1)
y1
- The new y-coordinate in pixels of this Viewport's top edgepublic final boolean setX2(double x2)
x2
- The new x-coordinate in pixels of this Viewport's right edgepublic final boolean setY2(double y2)
y2
- The new y-coordinate in pixels of this Viewport's bottom edgepublic final double getWidth()
public final double getHeight()
public final int getLeftEdge()
public final int getRightEdge()
public final int getTopEdge()
public final int getBottomEdge()
public final boolean rectangleIsVisible(double x1, double y1, double x2, double y2)
x1
- The x-coordinate of the region's left edgey1
- The y-coordinate of the region's top edgex2
- The x-coordinate of the region's right edgey2
- The y-coordinate of the region's bottom edge