• Surface.GetTextSize bug
    13 replies, posted
So, I have made a HUD and in certain dark areas of the map, when in vehicles and when looking at entities it will randomly become to small or way to large, Photos: Light area of map: https://steamuserimages-a.akamaihd.net/ugc/951841726612239479/E651AF70D735F65C7DDB43DFF490790BE058836E/ Dark area of map/when looking at entity/in vehicle: https://steamuserimages-a.akamaihd.net/ugc/951841726612243717/244BC1CF17AC39E0701289A95EA96275E7356555/ local function base() local job = LocalPlayer():getDarkRPVar("job") local name = LocalPlayer():Nick() or "" local location = LocalPlayer():GetNWString("sa_name") or "" local money = LocalPlayer():getDarkRPVar("money") or 0 local joblength = surface.GetTextSize(job); local namelength = surface.GetTextSize(name); local locationlength = surface.GetTextSize(location); local moneylength = surface.GetTextSize(money); local boxheight = 106; surface.SetDrawColor( 0, 0, 0, 125 ) surface.DrawRect( 20, ScrH() - 119, joblength + namelength + locationlength + moneylength + 145, boxheight )     surface.DrawOutlinedRect( 20, ScrH() - 119, joblength + namelength + locationlength + moneylength + 145, boxheight ) end
Try to call [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/SetFont]surface.SetFont[/url] first
https://steamuserimages-a.akamaihd.net/ugc/951841726612292490/3A0EC72E15690057AACE349D70667F1B9EB64A54/' Made the box even bigger when doing the things that make it longer
Because you're adding all the widths of the text together. You should use math.max to get the widest string.
Then send us your current code.
You're setting the font after you call surface.GetTextSize.
After you die for the first time it works however when you first spawn in it doesn't Code: surface.SetFont( "Trebuchet24" ) local function base() local job = LocalPlayer():getDarkRPVar("job") local name = LocalPlayer():Nick() or "" local location = LocalPlayer():GetNWString("sa_name") or "" local money = LocalPlayer():getDarkRPVar("money") or 0 local joblength = surface.GetTextSize(job); local namelength = surface.GetTextSize(name); local locationlength = surface.GetTextSize(location); local moneylength = surface.GetTextSize(money); local boxheight = 106; surface.SetDrawColor( 0, 0, 0, 125 ) surface.DrawRect( 20, ScrH() - 119, 335 + math.max(joblength, namelength, locationlength, moneylength), boxheight )     surface.DrawOutlinedRect( 20, ScrH() - 119, 335 + math.max(joblength, namelength, locationlength, moneylength), boxheight ) end
Okay I've fixed the issue, one more question. How can I make it so when the money bar extends the salary bar moves along so they don't collide so the money bar doesn't have to be long like that or have a big gap in between both bars https://i.gyazo.com/57174ab89deb32d71721e9732e53ad2c.png
Add the width of the money box to the X position of the salary box.
thank you
What would be the ScrW() for it? ScrW() - joblength + 60 doesn't work.
throw some res scaling shit like this into your code and play with ur position values local res = {     {name = "5:4", v1 = 5, v2 = 4, s = 2, ar = 1.25},     {name = "4:3", v1 = 4, v2 = 3, s = 2, ar = 1.33},     {name = "16:10", v1 = 16, v2 = 10, s = 5, ar = 1.60},     {name = "16:9", v1 = 16, v2 = 9, s = 5, ar = 1.78} } local mw, mh, d      for _,v in pairs(res) do     if math.Round( ScrW() / ScrH(), 2 ) == math.Round( v.ar, 2 ) and ScrW() != 740 and ScrH() != 480 then              print( "\n" )         print( ScrW(), ScrH() )         print( ScrW() / v.v1, ScrH() / v.v2 )         print( v.v1, v.v2 )         print( "\n" )                  mw = math.Round( ScrW() / v.v1 ) * v.s         mh = math.Round( ScrH() / v.v2 ) * v.s     else              mw, mh = 400, 400              end     d = v.ar end local x = ( ScrW() / d ) - ( mw + 7 ) --base x local tx = ( ScrW() / d ) - ( mw - 4 ) --base tx (text x)
Sorry, you need to Log In to post a reply to this thread.