Jump to content
  • Advertisement
Sign in to follow this  
Elit3d

Health bar graphics instead of text

This topic is 1394 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? 

Share this post


Link to post
Share on other sites
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!