/** * * Name a GameObject in the role of the Player object. Note that this is relevant only for the * viewport. If your game is larger than the screen, the viewport will follow the GameObject that * has been set as player. <br> * You have to add the GameObject to the game before assigning the player role.<br> * Only one GameObject can be the player. If you call this method for a second time, the player * role will switch to the newly specified object. player. * * @param player The player that should be added to the game. The location of this player is used * by the viewport. */ public final void setPlayer(MoveableGameObject player) { this.player = player; if (Viewport.useViewport) { Viewport vp = Viewport.getInstance(); vp.setPlayer(player); } }
/** * Set the dimensions of the game world.<br> * By default the dimensions will be set to the size of the screen. If you want to play a larger * game world, you can set the dimensions calleing this method in initialize().<br> * <b>Note</b>: You also need to set the world dimensions when you use a tile map. * * @param mapWidth, an int specifying the width of the game world * @param mapHeight, an int specifying the height of the game world */ public void setMapDimensions(int mapWidth, int mapHeight) { this.mapHeight = mapHeight; this.mapWidth = mapWidth; if (Viewport.useViewport) { Viewport vp = Viewport.getInstance(); vp.setBounds(0, 0, mapWidth, mapHeight); } }
/** * Set the tolerance of the positioning of the player. When tolerance is zero, the viewport moves * immediately when the player moves. When tolerance is 1, you can move to the edge of the screen * before the viewport moves. Values in between result in a smaller or bigger delay before the * viewport moves. <br> * Example: In a left-to right platform game, you may position the player at LEFT, CENTER. If you * set the horizontal tolerance at 0.3, you may move to the right 30% of the screen before the * viewport moves along. If you set vertical tolerance at 0.8, you can move 80% of the way up, * before the viewport moves up also.<br> * This method only has effect when you are using the viewport. * * @param ht horizontal tolerance, a value between 0 and 1 * @param vt vertical tolerance, a value between 0 and 1 */ public final void setPlayerPositionTolerance(double ht, double vt) { if (Viewport.useViewport) { Viewport vp = Viewport.getInstance(); vp.setPlayerPositionTolerance(ht, vt); } }
/** * When using a viewport, set the position of the player on the screen.<br> * In many games, the game world is bigger than the screen. When you specify the player position, * you can make the screen (viewport) move along with the player. The parameters tell how this * must be done. <br> * For the vpositioning (vertical adjustment) you can use Viewport.PLAYER_TOP, * Viewport.PLAYER_CENTER, Viewport.PLAYER_BOTTOM or Viewport.PLAYER_NOADJUST, if you don't want * adjustment of the player position in the vertical direction.<br> * For the hpositioning (horizontal adjustment) you can use Viewport.PLAYER_LEFT, * Viewport.PLAYER_CENTER, Viewport.PLAYER_RIGHT or Viewport.PLAYER_NOADJUST, if you don't want * adjustment of the player position in the horizontal direction.<br> * Note: if you position the player at one of the edges of the screen, like BOTTOM, this means * that you can not move out of the screen that way, but you can move up a bit. How much that is, * is specified by setPlayerPositionTolerance. * * @param hpositioning the horizontal postioning, or Viewport.PLAYER_NOADJUST if there is no * horizontal adjustment of the viewport * @param vpositioning the vertical postioning, or Viewport.PLAYER_NOADJUST if there is no * vertical adjustment of the viewport */ public final void setPlayerPositionOnScreen(int hpositioning, int vpositioning) { if (Viewport.useViewport) { Viewport vp = Viewport.getInstance(); vp.setPlayerPositionOnScreen(hpositioning, vpositioning); } }