Health bar graphics instead of text

Started by
4 comments, last by Paradigm Shifter 9 years, 4 months ago

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

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

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

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.

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.

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.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

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

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

This topic is closed to new replies.

Advertisement