draw.RoundedBox overlapping health and armor bars

Recently I’ve been working on a HUD. Currently I’m just drawing the boxes and adding in all the framework first.

I’ve came upon a crossroads though. I added a health bar and armor bar to the hud then added in a RoundedBoxEx. The problem is when I added in the box the box draws over the health bars and you cant really see the bars.

Like so:

Here is the code for the bars


//Defines and Draws the Armor and Health bars.  -- BEGINING --
function healthbar() 
    local health = LocalPlayer():Health()
        draw.RoundedBox(0, 190, ScrH() - 60 - 60, health, 15, Color(255,0,0,255))
        draw.SimpleText(health.."%", "default", 225, ScrH() - 60 - 60, Color(255,255,255,255))
end 
hook.Add("HUDPaint", "HealthBar", healthbar) 

function armorbar()
    local armor = LocalPlayer():Armor()
        draw.RoundedBox(0, 190, ScrH() - 42.5 - 42.5, armor, 15, Color(73,67,255,255))
        draw.SimpleText(armor.."%", "default", 225, ScrH() - 42.5 - 42.5, Color(255,255,255,255))
end
hook.Add("HUDPaint","ArmorBar", armorbar)
-- ENDINGING -- 

Does anyone know how this problem could be resolved?

Thanks.

Draw the rounded box first, then draw the health bars.

Since you’ve only shown us the drawing of the health and armour bars im assuming that your roundedbox code is after the code you posted?

Let me take a look real quick. I’ll try and assorting it in that manner.

[editline]24th May 2014[/editline]

It didn’t work :confused:

I have the same problem. You might want to parent it? I’m not sure if that will do it. I will try myself.

I don’t think that’s possible with draw. ? Is it?

Not with draw, I don’t think so–

Sorting it in this way.

[lua]
//example!!
function background()

draw.RoundedBoxEx(0, 0, ScrH() - 200,500, 250, Color(0,0,0,150))

end

function healthbar()
local health = LocalPlayer():Health()
draw.RoundedBox(0, 190, ScrH() - 60 - 60, health, 15, Color(255,0,0,255))
draw.SimpleText(health…"%", “default”, 225, ScrH() - 60 - 60, Color(255,255,255,255))
end

function armorbar()
local armor = LocalPlayer():Armor()
draw.RoundedBox(0, 190, ScrH() - 42.5 - 42.5, armor, 15, Color(73,67,255,255))
draw.SimpleText(armor…"%", “default”, 225, ScrH() - 42.5 - 42.5, Color(255,255,255,255))
end

function Main()
background()
healthbar()
armorbar()

end

hook.Add(“HUDPaint”,“Hud”,Main)
[/lua]

It worked! Thank you so much Royal. You’re amazing.

[editline]24th May 2014[/editline]

Also, I would be grateful if you could explain this part to me



function Main()
background()
healthbar() 
armorbar()



end

Is this just telling it what order for it to be structed in?
I’m fairly new to lua, but this looks to be very useful if it is what I think it is.

[editline]24th May 2014[/editline]

Here is the turn out:

You can write it in one function too, but if you divide them into different functions then you can read and understand them better.

[lua]

function Main()
–background()
draw.RoundedBoxEx(0, 0, ScrH() - 200,500, 250, Color(0,0,0,150))
–healthbar()
local health = LocalPlayer():Health()
draw.RoundedBox(0, 190, ScrH() - 60 - 60, health, 15, Color(255,0,0,255))
draw.SimpleText(health…"%", “default”, 225, ScrH() - 60 - 60, Color(255,255,255,255))
–armorbar()
local armor = LocalPlayer():Armor()
draw.RoundedBox(0, 190, ScrH() - 42.5 - 42.5, armor, 15, Color(73,67,255,255))
draw.SimpleText(armor…"%", “default”, 225, ScrH() - 42.5 - 42.5, Color(255,255,255,255))

end

hook.Add(“HUDPaint”,“Hud”,Main)

[/lua]

use draw.RoundedBoxEx – The last 4 arguments are whether or not you want x corner to show, meaning you can draw one box instead of two for the player model and the text above it.