Skip to content

Camera tracking player

Dollar0712 edited this page Sep 21, 2021 · 5 revisions

Purpose

This feature is designed to achieve the basic function of the camera to reasonably track the player. The camera shows the player a reasonable view of the screen as they move, giving them maximum access to the information within the game interface

Functionality

The following function shows how the camera is moved according to the player's position. It is worth noting that the camera's position is refreshed according to the game's frame refresh, so this function needs to be called in the "render" in MainGameScreen.java

  /**
   * reset the camera position when refreshing every frame
   * @param camera the CameraComponent of the map
   */
  public void resetCam(CameraComponent camera) {
    float playerX = player.getPosition().x;

    System.out.println(playerX);
    if (playerX >= 5 && playerX <= 35) {
      camera.getCamera().translate(playerX - camera.getCamera().position.x + 5, 0,0);
      camera.getCamera().update();
    }
  }

showcase

Tracking players beyond the border

Untracking players near the border

Table of Contents

Home

Introduction

Main Menu

Main Game Screen

Gameplay

Player Movement

Character Animations

Enemy Monster Design and Animations

Game basic functionalities

User Testing

GitHub Wiki Tutorial

Game Engine

Getting Started

Documentation

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally