Installation
cargo add bevy_health_bar
bevy_health_bar = "0.1.0"
Example
# Left Click | Right Click
cargo run --example basic
Usage
use bevy::prelude::*;
use bevy_health_bar::{ProgressBar, ProgressBarBundle, ProgressBarPlugin};
fn main() {
let mut app = App::new();
// Add Plugin
app.add_plugins((DefaultPlugins, ProgressBarPlugin));
// Spawn A Progress Bar
app.add_systems(Startup, spawn_health_bar);
// Control Progress Bar
app.add_systems(Update, update_health_bar);
app.run();
}
fn spawn_health_bar(mut commands: Commands, asset_server: Res<AssetServer>) {
// Need a camera to see scene
let camera_bundle = Camera2dBundle::default();
commands.spawn(camera_bundle);
// Sets value (and max value) of health bar
commands.spawn(ProgressBarBundle::new(
100.0,
asset_server.load("health_bar.png"),
));
}
fn update_health_bar(
mut query: Query<&mut ProgressBar>,
mouse_input: Res<Input<MouseButton>>,
dt: Res<Time>,
) {
if mouse_input.pressed(MouseButton::Left) {
for mut health_bar in query.iter_mut() {
health_bar.value -= 10.0 * dt.delta_seconds();
}
}
}
Features
Credits
- mz_eth for example health bar art