|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectandroid.gameengine.icadroids.renderer.Viewport
public class Viewport
The viewport follows a player object. When you use the viewport, make sure you have add a gameplayer to the game! Viewport is a Singleton, that means that if you want to use methods from it, you must make a new object like 'Viewport vp = Viewport.getInstance()'. To activate the viewport, you must set useViewPort to 'true'.
Field Summary | |
---|---|
static int |
PLAYER_BOTTOM
The constant for placing the player on the bottom side of the screen |
static int |
PLAYER_FIXED
The constant for fixing the viewport, it won't adjust to player |
static int |
PLAYER_HCENTER
The constant for placing the player horizontally centered |
static int |
PLAYER_LEFT
The constant for placing the player on the left side of the screen |
static int |
PLAYER_RIGHT
The constant for placing the player on the right side of the screen |
static int |
PLAYER_TOP
The constant for placing the player on the top side of the screen |
static int |
PLAYER_VCENTER
The constant for placing the player vertically centered |
protected int |
screenHeight
|
protected int |
screenWidth
|
static boolean |
useViewport
If you want to make use of the viewport, set useViewport on true |
protected float |
zoomFactor
The amount of zooming for the viewport. 1.0 is the standard view, lower than 1.0 will cause the viewport to zoom out, higher than 1.0 will cause the viewport to zoom in. |
Method Summary | |
---|---|
static Viewport |
getInstance()
Returns an instance of the private Viewport class. |
int |
getMaxX()
Gets right edge of the game world. |
int |
getMaxY()
Gets bottom edge of the game world. |
int |
getMinX()
Gets left edge of the game world. |
int |
getMinY()
Gets top edge of the game world. |
int |
getRandomX(int width)
Get random x between left edge of world and right edge minus the specified width. |
int |
getRandomY(int height)
Get random y between top edge of world and bottom edge minus the specified height. |
Point |
getViewportLocation()
Gets the position of the viewport. |
int |
getViewportX()
Gets the x-position of the viewport. |
int |
getViewportY()
Gets the y-position of the viewport. |
float |
getZoomFactor()
Gets the zoomfactor for zooming in. |
boolean |
isInViewport(GameObject item)
Check if the given gameitem lies within the viewport |
static int |
random(int range)
Generates a random integer between 0 (zero) and the given range, not including range. |
void |
setBounds(int minX,
int minY,
int maxX,
int maxY)
Set the boundaries of this game. |
void |
setPlayer(MoveableGameObject player)
Sets the object that will be the player character |
void |
setPlayerPositionOnScreen(int pos)
Sets the position of the player on the screen. |
void |
setPlayerPositionTolerance(double ht,
double vt)
Set the tolerance of the positioning. |
void |
setViewport(int x,
int y)
Set the position of the viewport manually. |
protected void |
setViewportLimits()
This method sets the viewport limits. |
void |
setZoomFactor(float zoomFactor)
Sets the zoomfactor for the viewport. |
void |
update()
This method centers the player in the middle of the viewport |
protected void |
updateViewportFirstTime()
This method sets the viewport for the first time. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean useViewport
public static final int PLAYER_HCENTER
public static final int PLAYER_VCENTER
public static final int PLAYER_LEFT
public static final int PLAYER_RIGHT
public static final int PLAYER_TOP
public static final int PLAYER_BOTTOM
public static final int PLAYER_FIXED
protected int screenWidth
protected int screenHeight
protected float zoomFactor
Method Detail |
---|
public void setPlayer(MoveableGameObject player)
player
- The object that will act as a playerpublic static Viewport getInstance()
protected final void setViewportLimits()
protected void updateViewportFirstTime()
public void update()
public static final int random(int range)
range
- the maximum number that may be returned
public final boolean isInViewport(GameObject item)
item
- the gameitem that needs to be checked
public final void setPlayerPositionOnScreen(int pos)
pos
- one of the following combinations:
PLAYER_FIXED
Viewport won't move. If your world is bigger than the screen,
the player can move out of sight on all sides!
PLAYER_TOP, PLAYER_VCENTER, PLAYER_BOTTOM
Player is at top, center or bottom of viewport. Horizontal
positioning is not controled, you can move out of view at the
sides!
PLAYER_LEFT, PLAYER_HCENTER, PLAYER_RIGHT
Player is at left, center or right of viewport. Vertical
positioning is not controled, you can move out of view at the
top or bottom!
PLAYER_TOP | PLAYER_LEFT, PLAYER_TOP | PLAYER_HCENTER,
PLAYER_TOP | PLAYER_RIGHT
PLAYER_VCENTER | PLAYER_LEFT, PLAYER_VCENTER | PLAYER_HCENTER,
PLAYER_VCENTER | PLAYER_RIGHT
PLAYER_BOTTOM | PLAYER_LEFT, PLAYER_BOTTOM | PLAYER_HCENTER,
PLAYER_BOTTOM | PLAYER_RIGHT
Combinations of vertical and horizontal positioning. The
following image illustrates this type of positioning:
public final void setPlayerPositionTolerance(double ht, double vt)
ht
- horizontal tolerance, a value between 0 and 1vt
- vertical tolerance, a value between 0 and 1public void setBounds(int minX, int minY, int maxX, int maxY)
minX
- the minimal horizontal coordinateminY
- the minimal vertical coordinatemaxX
- the maximal horizontal coordinatemaxY
- the maximal vertical coordinatepublic int getMinX()
public int getMaxX()
public int getMinY()
public int getMaxY()
public int getRandomX(int width)
width
-
public int getRandomY(int height)
height
-
public void setViewport(int x, int y)
x
- xpos of viewporty
- ypos of viewportpublic int getViewportX()
public int getViewportY()
public Point getViewportLocation()
public float getZoomFactor()
public void setZoomFactor(float zoomFactor)
zoomFactor
- the zoomfactor for the viewport.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |