Jump to content
• Advertisement

Public Group

# Health bar graphics instead of text

This topic is 1469 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

##### 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

##### 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

##### 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

##### Share on other sites

It should be width * currentHealth / maxHealth anyway? So if your max is 100 and current is 25 it will be 25/100 = 25% full...

#### Share this post

##### Share on other sites

• Advertisement

### Announcements

• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
31
3. 3
4. 4
5. 5
khawk
14
• Advertisement

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633647
• Total Posts
3013108
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!