Skip to content

UiHealthBar ​

The UiHealthBar class renders the player's health bar on the HUD. It listens for player tick updates and adjusts the inner bar width to reflect the current health percentage.

UiHealthBar private ​

Extends UiComponent.

Properties ​

NameTypeDescription
uiUiCurrent Ui instance. Inherited from UiComponent.
componentElemHTMLElementThe root #hud-health-bar DOM element. Inherited from UiComponent.
barElemHTMLElementThe .hud-health-bar-inner element whose width represents current health.
lastPlayerTick{ health: number, maxHealth: number }Cached previous player tick values. Initialized to { health: 100, maxHealth: 100 }.

Methods ​

constructor() ​

ts
function constructor(ui: Ui): void

Initializes the health bar, queries the inner bar element, and registers a listener for the playerTickUpdate event.

onPlayerTickUpdate() ​

ts
function onPlayerTickUpdate(playerTick: { health: number, maxHealth: number }): void

Updates the bar width percentage when health or maxHealth changes compared to the last tick. Caches the current tick for comparison on the next update.