• Advertisement

life bars

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

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
Advertisement
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
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
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
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
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
well all i did was scale the x axis down to get the effect i wanted

Share this post

Share on other sites

• Advertisement