Package com.deco2800.game.components
Class HealthBarComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.rendering.RenderComponent
com.deco2800.game.components.HealthBarComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable,Renderable,Comparable<Renderable>
Renders the entities health bar. Requires CombatStatsComponent
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreate()As soon as the entity is created we want to get its CombatStatsComponent.protected voiddraw(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 heathcom.badlogic.gdx.scenes.scene2d.ui.ProgressBarReturns the progress bar that represents the heath bar percentage to being displayedfloatZ index controls rendering order within a layer.voidsetCombatStatsComponent(CombatStatsComponent combatStatsComponent) voidsetRenderUtil(RenderUtil renderUtil) For setting a renderUtil if instantiated as a mock or otherwiseMethods inherited from class com.deco2800.game.rendering.RenderComponent
compareTo, dispose, getLayer, renderMethods inherited from class com.deco2800.game.components.Component
earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
HealthBarComponent
public HealthBarComponent(int width, int height) Constructs a new health bar- Parameters:
width- the width of the health bar in pixelsheight- the height of the healbar in pixels
-
-
Method Details
-
setCombatStatsComponent
-
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
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:
createin classRenderComponent
-
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:
drawin classRenderComponent- Parameters:
batch- Batch to render to.
-
getZIndex
public float getZIndex()Description copied from interface:RenderableZ index controls rendering order within a layer. Higher Z index is drawn on top.- Specified by:
getZIndexin interfaceRenderable- Overrides:
getZIndexin classRenderComponent- Returns:
- Z index
-