I want to make my game display a health bar instead of plain text, how would I properly go about this?
Health bar graphics instead of text
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
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