surface.DrawText
Example
Draws 'Hello World' on the screen. All functions in this example must be called for the draw to work flawlessly.
hook.Add( "HUDPaint", "drawsometext", function()
surface.SetFont( "Default" )
surface.SetTextColor( 255, 255, 255 )
surface.SetTextPos( 128, 128 )
surface.DrawText( "Hello World" )
end )
Example
Draws rainbow text without using surface.GetTextSize and surface.SetTextPos for every character (more efficient).
local text = "~Rainbow~"
hook.Add( "HUDPaint", "drawsometext", function()
surface.SetFont( "DermaLarge" )
surface.SetTextPos( 400, 128 )
for char = 1, #text do
local col = HSVToColor( ( ( RealTime() * 100 ) - char * 15 ) % 360, 1, 1 )
surface.SetTextColor( col.r, col.g, col.b ) -- Providing 3 numbers to surface.SetTextColor rather
surface.DrawText( string.sub( text, char, char ) ) -- than a single color is faster
end
end )