So my custom HUD is making my game lag.
Once I join my server, it doesn't lag at all but once I start switching jobs it starts to lag more each time I switch my job.
I think it's a HUD problem because when I remove my HUD, it doesn't happen.
Code:
[code]
local smooth = 0
local smooth2 = 0
local function hudPaint()
local health = math.Clamp(LocalPlayer():Health(), 0, 100)
local armor = math.Clamp(LocalPlayer():Armor(), 0, 100)
smooth = math.Approach(smooth, health, 50 * FrameTime())
smooth2 = math.Approach(smooth2, armor, 50 * FrameTime())
local w, h = 445, 20
local spacing = 32
local equation = (w)*(smooth/100)
local equation2 = (w)*(smooth2/100)
draw.RoundedBox(0, 10, 10, 550, 95, Color(40, 40, 40, 250)) -- Main Back
draw.RoundedBox(0, 10, 110, 150, 30, Color(40, 40, 40, 250)) -- Job Back
draw.RoundedBox(0, 165, 110, 150, 30, Color(40, 40, 40, 250)) -- Money Back
draw.RoundedBox(0, 320, 110, 150, 30, Color(40, 40, 40, 250)) -- NONE Back
draw.RoundedBox(0, 475, 110, 85, 30, Color(40, 40, 40, 250)) -- Rank Back
local avatar = vgui.Create( "AvatarImage", Panel )
avatar:SetSize( 64, 64 )
avatar:SetPos( 21, 27 )
avatar:SetPlayer( LocalPlayer(), 64 )
draw.RoundedBox(0, 100, 36, w, h, Color(40, 40, 40, 200)) -- Health
draw.RoundedBox(0, 100, 63, w, h, Color(40, 40, 40, 200)) -- Armor
draw.RoundedBox(0, 100, 36, equation, h, Color(192, 57, 43, 200)) -- Health
draw.RoundedBox(0, 100, 63, equation2, h, Color(22, 160, 133, 200)) -- Armor
-- [[ TEXT ]] --
draw.SimpleText(LocalPlayer():getDarkRPVar("job"), "Trebuchet24", 15, 113, Color(255, 255, 255, 255)) -- Job Text
end
hook.Add("HUDPaint", "DarkRP_Mod_HUDPaint", hudPaint)
[/code]
[code]
local avatar = vgui.Create( "AvatarImage", Panel )
avatar:SetSize( 64, 64 )
avatar:SetPos( 21, 27 )
avatar:SetPlayer( LocalPlayer(), 64 )
[/code]
[code]
if not createdAvatar then
local avatar = vgui.Create( "AvatarImage", Panel )
avatar:SetSize( 64, 64 )
avatar:SetPos( 21, 27 )
avatar:SetPlayer( LocalPlayer(), 64 )
createdAvatar = true
end
[/code]
^ I don't understand what you exactly mean by that :/
[QUOTE=VortexZ;52170695]^ I don't understand what you exactly mean by that :/[/QUOTE]
You're recreating the avatar image every frame.
Oh I make a createdAvatar = false outside of the func
[editline]1st May 2017[/editline]
I fixed this, thanks :D
Sorry, you need to Log In to post a reply to this thread.