Base Resource Label - UQdeco2800/2022-studio-3 GitHub Wiki

Introduction

To keep track of the base statistics of the game, a label has been designed which aims to constantly show the resource count in a way that aligns with the Atlantis theme and does not obstruct the players view.

At this stage, it is set up to display the accruing resource count of the player and all entities that can store wood, stone and metal. It can be modified to include currency or any other base stats to be decided.

image

Uses

Tracking: Track the overall count of resources/currency and display them Extension: Can be modified to include other game statistics such as health if required.

Modification

To add additional resources/currency...

Step 1: Declare the text labels, image labels and counter as a class variable, like so

public class ResourceCountDisplay extends UIComponent {

private Label goldCoinLabel;

private Image goldCoinImageLabel;

/* Modify these to update the resource count */
private int goldCoinCount = 100;

Step 2: Update the addActors() method to include each new resource. Be sure to use a font scaling of 1.5f to ensure consistency. Any images or icons should be sized 40 x 40. Don't forget to add the actors to the stage. An example is given below.

private void addActors() {

goldCoinLabel = new Label(String.format(" %d", goldCoinCount), skin);

goldCoinImageLabel = new Image(ServiceLocator.getResourceService().getAsset("images/gold-coin.png", Texture.class));

goldCoinLabel.setFontScale(1.5f); 

goldCoinImageLabel.setSize(40, 40);

stage.addActor(goldCoinLabel);
stage.addActor(goldCoinImageLabel);

Note: In the existing code, increase the resourceLabel HEIGHT to extend the background image.

Step 3: Add the new resource to the draw() method, as shown in existing code. On the x axis, resource image icons need to be offset by 20f whilst text needs to be offset by 10f. The image icons and the text icons have a difference of 10f on the y axis as shown below

private void draw(SpriteBatch batch) {

int screenHeight = Gdx.graphics.getHeight();
int screenWidth = Gdx.graphics.getWidth();

float offsetX = 10f;
float offsetY = 80f;

goldCoinImageLabel.setPosition(screenWidth - 200f + 20f, screenHeight - offsetY - 90f);
goldCoinLabel.setPosition(screenWidth - 200f + 50f + 10f, screenHeight - offsetY - 80f);

Step 4: Add each resource to the updatePlayerResourceUI(String resource, int count) method. Add each actor to the dispose() method.

This is straightforward, just add the line case "goldCoin -> goldCoinCount = count;