Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sparten11740/bevy_health_bar3d
Health bar for bevy implemented as a billboard shader
https://github.com/sparten11740/bevy_health_bar3d
bevy bevy-engine bevy-game game-development healthbar
Last synced: 6 days ago
JSON representation
Health bar for bevy implemented as a billboard shader
- Host: GitHub
- URL: https://github.com/sparten11740/bevy_health_bar3d
- Owner: sparten11740
- License: apache-2.0
- Created: 2023-05-03T19:57:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-07T11:42:27.000Z (6 months ago)
- Last Synced: 2024-12-04T23:23:09.120Z (18 days ago)
- Topics: bevy, bevy-engine, bevy-game, game-development, healthbar
- Language: Rust
- Homepage: https://crates.io/crates/bevy_health_bar3d
- Size: 400 KB
- Stars: 34
- Watchers: 2
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[![Checks](https://github.com/sparten11740/bevy_health_bar3d/actions/workflows/checks.yml/badge.svg)](https://github.com/sparten11740/bevy_health_bar3d/actions/workflows/checks.yml) [![Release](https://github.com/sparten11740/bevy_health_bar3d/actions/workflows/release.yml/badge.svg)](https://github.com/sparten11740/bevy_health_bar3d/actions/workflows/release.yml)
## bevy_health_bar3d
Health Bar plugin for Bevy 3D. Despite its name, this plugin is universally applicable. It can be used to render a bar
for any value that can be represented as percentage. Can be freely sized, supports horizontal or vertical orientation,
custom fore- and background colors, and an optional border with configurable thickness and color. Works with
split-screens
or layered cameras out of the box.## Bevy Compatibility
| Bevy Version | Crate Version |
|--------------|--------------:|
| `0.14` | >= `3.3.0` |
| `0.13` | `3.2.0` |
| `0.12` | `2.0.0` |
| `0.11` | `1.2.0` |
| `0.10` | `1.1.0` |
| `0.9` | `1.0.0` |## Usage
Implement the `Percentage` trait for the component you want to track and pass the type of your component
to the plugin on instantiation:```rust
use bevy_health_bar3d::prelude::{HealthBarPlugin, Percentage};#[derive(Component, Reflect)]
struct Health {
max: f32,
current: f32,
}impl Percentage for Health {
fn value(&self) -> f32 {
self.current / self.max
}
}fn main() {
App::new()
// add multiple times to track further component types
.add_plugins((HealthBarPlugin::::default(), HealthBarPlugin::::default()))
// set a different color for the Mana bar
.insert_resource(ColorScheme::::new().foreground_color(ForegroundColor::Static(Color::BLUE)))
.run();
}
```Spawn a mesh, the component to be tracked, and a `BarSettings` component to configure the look & feel of your bar.
```rust
fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
commands.spawn((
PbrBundle {
mesh: meshes.add(Sphere { radius }),
// ...
},
Health {
max: 10.,
current: 2.,
},
BarSettings:: {
width: 5.,
offset: 2.,
orientation: BarOrientation::Vertical, // default is horizontal
..default()
},
));
}
```Note the generic parameter of `BarBundle`. It is used to associate the configuration with the component it is tracking
and necessary to support multiple bars per entity.That's it! Updates to the values of your component will be automatically propagated through to the bar.
## Examples
Examples can be found [here](https://github.com/sparten11740/bevy_health_bar3d/tree/main/examples).
To run an example for web, first install cargo-make (`cargo install cargo-make`) and then call
`cargo make web