Drawing Avatar on HUD Efficiently

Hi, I’m currently designing a custom HUD for my server. How would I go about drawing the localplayer’s steam avatar efficiently? I know it’s done in Derma but I can’t implement it that way as I do not know how to do it efficiently (can’t do it in HUDPaint because that would cause a memory leak).

All answers are appreciated, thank you.

Create the avatar image outside of hud paint so you only create it once. Set it to painted manually so it doesn’t draw (look on the wiki for ‘manual’ and you’ll find it). In hud paint you then tell it to paint.

So, like this?



local function drawProfilePic()
	Avatar = vgui.Create("AvatarImage", Frame)
        Avatar:SetPaintedManually(true)
	Avatar:SetSize(64, 64)
	Avatar:SetPos(100, 100)
	Avatar:SetPlayer(LocalPlayer(), 64)]]
end

local function bringToLife()
	if (LocalPlayer():Alive()) then
		Avatar:PaintManual()
	end
end

hook.Add("HUDPaint", "DrawTheHUD", bringToLife)


i don’t know if this works, but the princip is more like this

[lua]
local a = vgui.Create(“AvatarImage”, Frame)

local function bringToLife()
if (LocalPlayer():Alive()) then
a:SetPaintedManually(true)
a:SetSize(64, 64)
a:SetPos(100, 100)
a:SetPlayer(LocalPlayer(), 64)]]
end
end

hook.Add(“HUDPaint”, “DrawTheHUD”, bringToLife)
[/lua]

If you’re gonna have an avatar on the HUD, might as well go full out Derma then.

Thanks, I’ll try that.

I’ve already got a pretty good HUD set up without using derma. Complete with custom ammo and agenda displays.