# life bars

## Recommended Posts

lodoss118    102
how i got some marvel vs capcom 2 life bars i am bit confused on how to program them basically i have obe long bar how would i do that effect to make it smaller everytime u don;t get hit?

#### Share this post

##### Share on other sites
Daaark    3553
Which part don't you understand?

Draw the empty bar. Then draw the full one on top, but only draw as much of it as there is life in the player. You determine the life by adjusting a varible everytime you detect that someone has been hit.

#### Share this post

##### Share on other sites
lodoss118    102
its ok i fixed it what i meant was i have one really big bar not broken into little bits and i wanted it to go down when i got hit

#### Share this post

##### Share on other sites
kelcharge    180
It would help people to help you if you use some correct spelling and grammar. To solve your question, you draw the image of the bar something like (x, y, w, h) which are the X and Y positions and the Width and Height positions. Have your width be in a variable like w. Then when the person is hit subtract from your width variable. It shows the effect of the life bar going down.

#### Share this post

##### Share on other sites
Necrosis    150
The way I'm planning on doing lifebar displays on one of my projects, is to add a clipper on the lifebar that changes lengths based on the percentage of the life. So if the life is at 100% the clipper is full length, but if the life is down to 50%, it shortens the clipper length by 50% which will only draw the first half of the bar.

#### Share this post

##### Share on other sites
deadimp    310
I agree with SirSmoke in using proportions. They're easy to create, use, and change.
How to determine the width of your health bar (USHORT health_width) when you have: Health Bar Maximum Width (USHORT health_max_width), Health Max (USHORT health_max), Health (USHORT health).
health_width=(health_max_width*health)/health_max;

You needn't worry about floating-point operations, because ordering it like this will keep it accurate (to an integral degree) with integral operations. Also, the parenthesis aren't really needed.

NOTE: "USHORT" = "unsigned short" in C++ (typedef in <windows.h>)

#### Share this post

##### Share on other sites
lodoss118    102
well all i did was scale the x axis down to get the effect i wanted

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