Hello,
I'm looking to add an image to my HUD.
I've already found that "[CODE]surface.SetTexture(surface.GetTextureID("gui/silkicons/heart"))[/CODE]" but I have an error in my console, any idea?
Error : [CODE]--- Missing Vgui material gui/silkicons/heart[/CODE]
Myckael,
(Sorry for my bad english, i'm french^^)
The silkicon is icon16/heart.png. Also, don't define your material within your drawing hook. It'll be heavy performance wise if you're calling it every frame.
Better off doing it like this:
[code]
-- outside of your hook
local heartTex = Material("icon16/heart.png") -- surface.GetTextureID doesn't work with .png's
-- and in your hook
surface.SetTexture(heartTex) -- just set the texture to the one we defined above
[/code]
Don't use SetTexture, that barely ever works for anything, try using SetMaterial:
[CODE]
local texture = Material( "icon16/heart.png" )
hook.Add( "HUDPaint", "example", function()
surface.SetDrawColor( 255, 255, 255, 255 ) -- solid white
surface.SetMaterial( texture ) -- set the current material to the heart
surface.DrawTexturedRect( 0, 0, 50, 50 ) -- this draws a heart in the top left (0, 0) of size 50 x 50
end )
[/CODE]
Note the icon16 icons are only meant to be displayed in 16x16
[QUOTE=MPan1;52111531]Don't use SetTexture, that barely ever works for anything, try using SetMaterial:
[CODE]
local texture = Material( "icon16/heart.png" )
hook.Add( "HUDPaint", "example", function()
surface.SetDrawColor( 255, 255, 255, 255 ) -- solid white
surface.SetMaterial( texture ) -- set the current material to the heart
surface.DrawTexturedRect( 0, 0, 50, 50 ) -- this draws a heart in the top left (0, 0) of size 50 x 50
end )
[/CODE]
Note the icon16 icons are only meant to be displayed in 16x16[/QUOTE]
Thanks you, and if i want to add an material? Any exemple : [url]https://cdn1.iconfinder.com/static/e9bcefc0c5591114fcd0b4b0aff67962/assets/img/extended-library/icon.svg[/url] where can i put the .png?
[editline]16th April 2017[/editline]
I have another problem, the heart appears below the roundedbox :/
That file is a .svg, you'll first need to find a way to save or convert it to a .png file, but when you do, you just need to put it in here:
[CODE]Steam/SteamApps/Common/GarrysMod/garrysmod/materials/[/CODE]
And then do
[CODE]
local texture = Material("icon.png")
[/CODE]
[editline]16th April 2017[/editline]
[QUOTE=Myckyy;52111630]I have another problem, the heart appears below the roundedbox :/[/QUOTE]
Post the code? You just need to draw it after drawing the rounded box?
[QUOTE=MPan1;52111644]That file is a .svg, you'll first need to find a way to save or convert it to a .png file, but when you do, you just need to put it in here:
[CODE]Steam/SteamApps/Common/GarrysMod/garrysmod/materials/[/CODE]
And then do
[CODE]
local texture = Material("icon.png")
[/CODE]
[editline]16th April 2017[/editline]
Post the code? You just need to draw it after drawing the rounded box?[/QUOTE]
Oh, it's my bad, I put it before the rounded box, thanks you guy, havenice day :)
Sorry, you need to Log In to post a reply to this thread.