Repository navigation
Widgets HealthBarWidget
HealthBarWidget is a world-space health bar that automatically follows a Sprite. Unlike ProgressBarWidget, it works with a real maximum/current health pair and is designed specifically for game entities.
These examples assume you already have a
RenderSurfaceHostBasenamedhostand, where appropriate, aViewnamedview, aSceneLayernamedsceneLayer, or aSpritenamedsprite.
using System.Drawing;
using Gondwana.Widgets.Hud;
var healthBar = new HealthBarWidget(
host,
sprite,
maximum: 100f,
size: new Size(72, 10));
healthBar.Value = 75f;The widget automatically repositions itself as the sprite moves.
spriteHealth -= damage;
healthBar.Value = spriteHealth;Values are clamped between 0 and Maximum.
float percent = healthBar.Fraction;healthBar.Maximum = 150f;
healthBar.Value = 150f;healthBar.OffsetPx = new Point(0, -4);
healthBar
.SetFillColor(Color.OrangeRed)
.SetValue(90f);You normally do not need to reposition it manually, but RefreshPosition() is available if some external visual change requires an immediate refresh.
The widget listens to its target sprite. When the sprite is disposed, the health bar disposes itself as well.
| Member | Purpose |
|---|---|
Target |
Sprite being followed. |
Maximum / Value
|
Health range and current health. |
Fraction |
Current normalized health from 0 through 1. |
Size |
Bar dimensions in world pixels. |
OffsetPx |
Additional offset from the normal centered-above-sprite position. |
TrackBoundsWorld / FillBoundsWorld
|
Current world bounds. |
SetFillColor() |
Changes the health fill color. |
- Home
- Make Your First Game in 30 Minutes
- Engine Architecture Overview
- Game Hosts and Application Startup
- Gondwana Engine Lifecycle
- Gondwana CLI Cheatsheet
- Using Gondwana with ChatGPT and Codex
Core Concepts
Systems
Rendering
Widgets
-
Controls
-
Dialogs
- AboutBox
- ConversationBox
- DialogBox — base class for custom dialogs
-
Hud
-
Layout
-
Menus
-
Overlays