Skip to content

Player Camera

yuezhang7 edited this page Sep 1, 2021 · 7 revisions

In games, players may view the world through a specific way. Depending on the genre or style of the game, the 'view' can vary in perspective (first person vs third person), FOV and panning. This is what is also known as the 'camera'.

In Retroactive, players are subjected to an isometric third person camera that centres on their character. This is because a third person view can allow the player more visiblity of the room and their contents, as opposed to a restricting first person camera.

How It Works

Step1: Change Entity player from private to public under the class ForestGameArea in order to make it can be accessed from non-child class.

public Entity player;

Step2: In the class ScreenAdapter, create new properties entityPlayer and PLAYER_POSITION

private Entity entityPlayer;
private Vector2 PLAYER_POSITION;

Step3: Make entityPlayer to be player and set camera tracking player position

entityPlayer = forestGameArea.player;
PLAYER_POSITION = entityPlayer.getPosition();
renderer.getCamera().getEntity().setPosition(PLAYER_POSITION);

Step4: Overriding the method render that set camera tracking player's position

PLAYER_POSITION = entityPlayer.getPosition();
renderer.getCamera().getEntity().setPosition(PLAYER_POSITION);

Design Process

  1. Use the main camera as a sub-object of the Player.
  2. Fix the position and angle of the camera.
  3. Set the player's perspective as the main camera to keep the player in the centre of the screen.

Results

Camera Demo

Clone this wiki locally