ickshonpe / bevy_simple_stat_bars

library for drawing health bars etc above sprites
MIT License
6 stars 7 forks source link
2d bevy game-development graphics sprites

stat bars

Simple library just for drawing stat bars above sprites to display their health or whatever.

Only goal is to be an easy to use crate that you can drop into any project and have stat bars in less than ten minutes.

basic how-to

Add the StatBarsPlugin to your app, then you can spawn stat bars like so:

commands
.spawn_bundle((
    // color of the statbar (required)
    StatBarColor(Color::GREEN), 

    // color of the empty part of the statbar (optional)
    StatBarEmptyColor(Color::BLACK),

    // color and thickness of the border (optional)
    StatBarBorder { color: Color::DARK_GRAY, thickness: 3.0 },

    // initial value (0.0 is empty, 1.0 is full) (required) 
    StatBarValue(1.0),

    // length and thickness of the bar (required)
    StatBarSize { full_length: 50.0, thickness: 6.0 },

    // entity the statbar tracks (required)
    StatBarSubject(player_entity),

    // position relative to the subject entity (40 units above in this case) (optional)
    StatBarPosition(40.0 * Vec2::Y),

    // takes a |&Component| -> f32 closure, which is called each tick with the
    //      respective component of the subject entity.
    //      returned f32 value is used to update StatBarValue
    // (optional, can leave out and just update StatBarValue manually)
    component_observer(|hp: &Hp| hp.current as f32 / hp.max as f32)
));   

and they should just work.

Notes

There is a complete-ish working example in the /examples folder.

Any feedback / improvement suggestions / code submissions will be super appreciated.