Health bar going down wrong way - draw.RoundedBox HUD
6 replies, posted
Here's the code
draw.RoundedBox(0, 20, ScrH () - 153, 20, 130 * DrawHealth / 100, Color(255,0,0,255))
https://files.facepunch.com/forum/upload/256040/4895a3e8-1e5f-4b85-a953-633fe5eee310/fb07a0861b0328c4508739c4fa217c73.png
As you can see, the problem is that the health goes from 100% being full red, to 15% health but it's at the top rather than it being at the bottom where it should be.
I can't seem to change the Y size to make it go the other way because it will just disappear or glitch. Same thing with putting a negative value. Thanks!
Did you try to put the * Drawhealth at ScrH() instead?
I tried just now, did you mean like this?
draw.RoundedBox(0, 20, ScrH() * DrawHealth / 100 - 153, 20, 130, Color(255,0,0,255))
If so, it just causes the whole red bar to go higher outside of the HUD box each time I damage myself
https://files.facepunch.com/forum/upload/256040/1eb04b09-73ce-47f0-a0a5-123cc432cf31/f2b3dbce7583b0256ddee863c77e555a.png
You also have surface.DrawTexturedRectRotated, but somehow the healthbar will close in and not go from top to right. Maybe someone else can help you out.
I'll see what I can do with it, thank you for your help
local health_bar_len = 130 * health / 100
draw.RoundedBox(0, 20, ScrH () - 23 - health_bar_len, 20, health_bar_len, Color(255,0,0,255))
What you're going to need to do is offset your box's Y position by the max height - its current height.
So if the full bar is 100 pixels tall, and your current health makes the bar 25 pixels tall, you'll need to move the health bar down 75 pixels to account for that.
I'll leave the exact math to you, but that's the theory behind it
Sorry, you need to Log In to post a reply to this thread.