Resolved Help with blending

rcombs4

Well-known member
Joined
Aug 6, 2008
Messages
189
Programming Experience
3-5
I need help with a little game I'm working on. I'm working on a basic life meter. Its just the same as we have seen forever. When you have all you life the bar is full as you loose life the bar goes down. I want the far left of the bar to be red and blended up to green. I've got the blending done and it looks great. I used a combination of the LinearGradientBrush and the Blend class to get the color right. Ive used a rectangle with the width being my %of life. So when i have 100 life the bar is full. When my life gets down to say 20 the bar is only 20 pixles wide.

Now my issue is that when you start to loose life the gradient percentages remain the same. When you have full life the bar is 20% red and 80% green. As i loose life those percentages remain the same. So instead of having the border between the red and green stay in the same position the border changes.

I imagine I can fix the issue by re calculating the gradient each time but it just seems like I shouldnt have to do that. I think if i coud have the gradient be pixel based not percentaged based it would work.

Any input would be greatly appreciated.

Thanks
 
Last edited:
The Rectangle of the LinearGradientBrush defines the gradient area (set by constructor or property), this can represent 100% of the bar always. When you fill a smaller rectangle with this brush the absolute gradient blend will not change.
 
I dont have access to my code now but your right. I must be doing something wrong in the code.


Thanks!
 
Back
Top