• Vertical text?
    6 replies, posted
If I wanted to draw some vertical text in a HUD, how would I make the text do that?
Newlines?
No, spacing [t]http://images.akamai.steamusercontent.com/ugc/263838879864859413/C8EEC0087AB8B35994E27A24CD255CB9E477B9D3/[/t] [lua]draw.DrawText("P\nl\na\ny\ne\nr\ns\na\nl\ni\nv\n", "PRS_TDM_HUD_playersAlive", 960*wMod, 18*hMod, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER );[/lua]
Do you mean the spacing is too much? I could do a quick spacing-fix, hang on...
Split all the characters of the string up and use a for loop and the surface library to get the height draw the char and increment the y poz
[QUOTE=MPan1;50495789]Do you mean the spacing is too much? I could do a quick spacing-fix, hang on...[/QUOTE] Yes, compared to normal text, there's a lot of spacing between the characters with newlines
Try this: [CODE] function DrawVerticalText( text, font, x, y, col ) surface.SetFont( font ) surface.SetTextColor( col ) local prevh = 0 -- previous height for i = 1, #text do local w, h = surface.GetTextSize( string.sub( text, 1, i-1 ) ) prevh = prevh + h - 3 -- change the -3 to make the spacing bigger or smaller surface.SetTextPos( x, y+prevh ) surface.DrawText( string.sub( text, i, i ) ) end end [/CODE] It just splits the string up and draws a different character for each letter in the string, hopefully it'll do what you want it to [editline]11th June 2016[/editline] Lol, this does exactly what rtm516 says, sort of ninja'd [editline]11th June 2016[/editline] Also, if you wanted the text to be drawn centered on the x axis: [CODE] function DrawVerticalTextCentered( text, font, x, y, col ) surface.SetFont( font ) surface.SetTextColor( col ) local prevh = 0 -- previous height for i = 1, #text do local w, h = surface.GetTextSize( string.sub( text, 1, i-1 ) ) local actualw, actualh = surface.GetTextSize( string.sub( text, i, i ) ) prevh = prevh + h - 3 -- change the -3 to make the spacing bigger or smaller surface.SetTextPos( x-actualw/2, y+prevh ) surface.DrawText( string.sub( text, i, i ) ) end end [/CODE]
Sorry, you need to Log In to post a reply to this thread.