• Need to add an image to a HUD.
    8 replies, posted
Hi, I'm trying to make a HUD for my gamemode and would like an image. This is the code I have used: [B] local tex = surface.GetTextureID("garrysmod/materials/swords.vtf") function drawTexture() surface.SetTexture(tex) surface.SetDrawColor(255,255,255,255) surface.DrawTexturedRect(ScrW()*0.5-32,ScrH()*0.5-32,64,64) end hook.Add("HUDPaint","DrawTheTexture",drawTexture)[/B] Please help! :)
try [code] local mat = Material("swords.vmt") function drawTexture() surface.SetMaterial(mat) surface.SetDrawColor(Color(255,255,255,255)) surface.DrawTexturedRect(ScrW()/2 -32, ScrH()/2 -32, 64, 64) end hook.Add("HUDPaint", "DrawTheTexture", drawTexture)[/code] not sure if it works but its something
Didn't work :/
What files have you got? What did the code do? Errors? Purple Checkerboard?
What do you mean what files have I got and there is a purple checkboard in the middle of the screen.
Don't add extensions when you use .vtf/.vmt combo. I would suggest using .png and Material("path.png") instead though.
I read on this other thread that vtf was required? [editline]12th April 2014[/editline] Could you write out how you would do the code, I would appreciate it, I'm new to coding. :) [editline]12th April 2014[/editline] Could you write out how you would do the code, I would appreciate it, I'm new to coding. :)
Use the code above but replace the .vmt with .png and convert your image to .png [lua] local mat = Material("swords.png") function drawTexture() surface.SetMaterial(mat) surface.SetDrawColor(Color(255,255,255,255)) surface.DrawTexturedRect(ScrW()/2 -32, ScrH()/2 -32, 64, 64) end hook.Add("HUDPaint", "DrawTheTexture", drawTexture) [/lua]
That works, thank-you so much!
Sorry, you need to Log In to post a reply to this thread.