Skip to content

Player UI

Su LAN edited this page Aug 30, 2021 · 6 revisions

Purpose

The player UI contains elements that describe the current state of the game for the player. Currently, these contain the current 'level' the player is on and their health as floating text.

Improvements

The current implementation of health in the game is just a number. The health bar will be extended to be a bar that depletes as the health of the player decreases and fills when (if) the players' health increases. The players' health will be reset to full if they change to a new level, or restart the level. The HP bar function is base on the percentage

Adding HP images to the game

Use AssetManager to create a manager to manage the Texture. Assets are reference counted. This also means that if you load an asset several times, it will only take up memory once!

public static AssetManager manager =  new  AssetManager ();

Create the pixmap to import the texture the game need.

public static Pixmap pixmap = new Pixmap(3,1, Pixmap.Format.RGBA8888);
public static Texture pixmaptex = new Texture(pixmap);
public static TextureRegion h= new TextureRegion(pixmaptex);

After creating the asset manager we need to load the images we need to the manager. The AssetManager Class provides a function to help you add the resource to the manager.
This is an example to load a texture to the manager

manager.load("images/file.png", Texture.class);

Remember you need to tell the manager you finished load all the resources.

manager.finishLoading();

Set the HP images to above the Character and make changes with the Health number.
The first thing to do is get the current health percentage.

double health = entity.getComponent(CombatStatsComponent.class).getHealth();
double hp = health / entity.getComponent(CombatStatsComponent.class).getMaxHealth();

Then let's make the image of the hp bar change with the health in Draw Method.

if (hp>0.9){
   textureRegion.setTexture(manager.get("images/100.png", Texture.class));
   batch.draw(textureRegion,entity.getPosition().x-1, entity.getPosition().y+1);
}

Health Bar Design

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