• Two text colors on one line?
    5 replies, posted
I'm making a hud and i want the players balance and salary on the same line but in two different colors, is there a way about doing this?
Use two separate DrawText calls, but put one after the other.
[QUOTE=code_gs;52569634]Use two separate DrawText calls, but put one after the other.[/QUOTE] Wouldn't that require me to choose two different positions for the text? I want them to be right next to eachother no matter the value much like they would if they were in the same drawtext call
You can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/GetTextSize]surface.GetTextSize[/url] to get the width of the first section so you can place the second right after.
Find out the width of the first line ([url]http://wiki.garrysmod.com/page/surface/GetTextSize[/url]), then find out the width of "blank" space in given font. So X location of second call would be: x = x+1stlinewidth+widthofspacebar (or simply include the spacebar in the second call.) #edit code, half assed, idk if its gonna work. [code] local text1 "I am red " local text2 = " and I am green" surface.SetFont("font") surface.SetTextColor(255,0,0,255) surface.SetTextPos(20,40) surface.DrawText(text1) local x,y = surface.GetTextSize( text1 ) surface.SetTextColor(0,255,0,255) surface.SetTextPos(20+x,40) surface.DrawText(text2) [/code]
[QUOTE=RaKo;52569672]Find out the width of the first line ([url]http://wiki.garrysmod.com/page/surface/GetTextSize[/url]), then find out the width of "blank" space in given font. So X location of second call would be: x = x+1stlinewidth+widthofspacebar (or simply include the spacebar in the second call.) #edit code, half assed, idk if its gonna work. [code] local text1 "I am red " local text2 = " and I am green" surface.SetFont("font") surface.SetTextColor(255,0,0,255) surface.SetTextPos(20,40) surface.DrawText(text1) local x,y = surface.GetTextSize( text1 ) surface.SetTextColor(0,255,0,255) surface.SetTextPos(20+x,40) surface.DrawText(text2) [/code][/QUOTE] Thanks, there were a couple problems but i fixed em
Sorry, you need to Log In to post a reply to this thread.