Class HealthBarComponent

All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable, Renderable, Comparable<Renderable>

public class HealthBarComponent extends RenderComponent
Renders the entities health bar. Requires CombatStatsComponent
  • Constructor Details

    • HealthBarComponent

      public HealthBarComponent(int width, int height)
      Constructs a new health bar
      Parameters:
      width - the width of the health bar in pixels
      height - the height of the healbar in pixels
  • Method Details

    • setCombatStatsComponent

      public void setCombatStatsComponent(CombatStatsComponent combatStatsComponent)
    • getProgressBar

      public com.badlogic.gdx.scenes.scene2d.ui.ProgressBar getProgressBar()
      Returns the progress bar that represents the heath bar percentage to being displayed
      Returns:
      the progress bar representing health
    • setRenderUtil

      public void setRenderUtil(RenderUtil renderUtil)
      For setting a renderUtil if instantiated as a mock or otherwise
      Parameters:
      renderUtil - the instance to use
    • create

      public void create()
      As soon as the entity is created we want to get its CombatStatsComponent. This means the order in which you add the HealthBarComponent and CombatStatsComponent is important. You are expected to have CombatStatsComponent first added. fullHealth refers to the initial health of the entity when constructed
      Overrides:
      create in class RenderComponent
    • draw

      protected void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
      When the render calls draw we render the health bar with any adjustments made so it reflects the remaining or added heath
      Specified by:
      draw in class RenderComponent
      Parameters:
      batch - Batch to render to.
    • getZIndex

      public float getZIndex()
      Description copied from interface: Renderable
      Z index controls rendering order within a layer. Higher Z index is drawn on top.
      Specified by:
      getZIndex in interface Renderable
      Overrides:
      getZIndex in class RenderComponent
      Returns:
      Z index