Sign in to follow this  

Health bar graphics instead of text

This topic is 1109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to make my game display a health bar instead of plain text, how would I properly go about this? 

 

that depends on how you want it to look, the easiest would probably be to draw a quad/rectangle that is: maxwidth * (currenthp / maxhp) wide

Share this post


Link to post
Share on other sites

You're going to have to be alot more specific if you want somebody to show you in code, since we don know what graphics library or language you are using.

 

The simplest way is to first draw a background rectangle of a certain width (we'll call the width w).  Then on top of that you can draw another rectangle in a different colour.  The width of this rectangle will be w * total_life / current_life.

 

I am using SDL and from what you told me with the w*total life, I shall try to get something working.

Share this post


Link to post
Share on other sites

You're going to have to be alot more specific if you want somebody to show you in code, since we don know what graphics library or language you are using.

 

The simplest way is to first draw a background rectangle of a certain width (we'll call the width w).  Then on top of that you can draw another rectangle in a different colour.  The width of this rectangle will be w * total_life / current_life.

Your equation will end up generating a NAN on player death.When I create progress bars like this I generate a increment variable and then multiply that with the current health value to not generate that NAN.

 

So the equation becomes currentHealt * ( w / maxHealth), you can also use the current health value to index a 1D texture if you plan to do some color interpolation to indicate good or bad health status.

Share this post


Link to post
Share on other sites

This topic is 1109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this