Hi guys. I have a problem. When i change position in Category:AvatarImage i have two or more avatar images. How to fix or it is fine?
local Avatar = vgui.Create( "AvatarImage", Panel )
Avatar:SetSize( 64, 64 )
Avatar:SetPos( 4, 4 )
Avatar:SetPlayer( LocalPlayer(), 64 )
One way of doing this:
local Avatar
if IsValid(Avatar) then Avatar:Remove()
Avatar = vgui.Create( "AvatarImage", Panel )
Avatar:SetSize( 64, 64 )
Avatar:SetPos( 4, 4 )
Avatar:SetPlayer( LocalPlayer(), 64 )
When you are refreshing the code, you are creating multiple avatars, so make sure you remove any existing ones before adding one again.
As I said, there are many ways
The AvatarImage can be a reason of lags?
You are likely drawing the HUD using the HUD Paint hook but AvatarImage is a panel so you are creating a new panel every frame the HUD is in view.
This question has been answered many many times before but in different ways, try googling the keyword AvatarImage around facepunch.
You said EVERY FRAME. Can i make it only once and how?
Scroll up a few posts, I already told you yesterday
function HUD1()
local Avatar
if IsValid(Avatar) then Avatar:Remove()
Avatar = vgui.Create( "AvatarImage", Panel )
Avatar:SetSize( 64, 64 )
Avatar:SetPos( 27, 600)
Avatar:SetPlayer( LocalPlayer(), 128 )
end
end
hook.Add("HUDPaint", "HUD1", HUD1)
Your code doesn't work. Look.
https://files.facepunch.com/forum/upload/114477/623b28c4-5d8e-4a9b-910c-5e9c00f813bd/изображение.png
vgui is an object you create once. Like a window, button or spawnmenu option.
if you place vgui.Create inside a HUDPaint .. you create another AvatarImage every frame.
So at 60FPS that is:
1 sec = 60 AvatarImages
10sec = 600 AvatarImages
1 min = 3.600 AvatarImages
5 min = 18.000 AvatarImages
30min = 108.000 AvatarImages
Yes .. yes it will cause lag and at some point; crash or out_of_memory error.
If you dont bother reading whole posts, why the heck should we even help you? I told you to use Ia_grib's code, yet you did not. Also try to keep your problems in one thread, no need to flood the forums
Use This
Avatar:ParentToHUD()
Sorry, you need to Log In to post a reply to this thread.