Align text to center
So i want do draw text above players. its going great soo far BUT i want to align the text to the middle:
Screen capture
Soo far codeside i have this:
function DrawInfo()
for id, target in pairs(ents.FindByClass("Player")) do
local ply = LocalPlayer()
if target:Alive() then
local name = tostring(target:Nick())
local targetPos = target:GetPos() + Vector(0,0,90)
local targetDistance = math.floor((ply:GetPos():Distance(targetPos))/40)
local targetScreenpos = targetPos:ToScreen()
// Draw Name
surface.SetTextColor( 255,255,255,100 )
surface.SetFont( "DermaLarge" )
surface.SetTextPos( tonumber(targetScreenpos.x ), tonumber( targetScreenpos.y ))
surface.SetTextColor( 255,255,255,255-targetDistance*25 )
surface.DrawText(target:Name())
// Draw Rank
surface.SetTextColor( 255,255,255,100 )
surface.SetFont( "DermaDefault" )
surface.SetTextPos( tonumber(targetScreenpos.x ), tonumber( targetScreenpos.y + 30 ))
surface.SetTextColor( 255,255,255,255-targetDistance*25 )
surface.DrawText(target:GetUserGroup())
else
end
end
end
hook.Add("HUDPaint","DrawNames",Drawinfo)
Use surface.GetTextSize on target:Name() and offset the X value in your SetTextPos with it.
i used draw.DrawText instead that does what i needed
Sorry, you need to Log In to post a reply to this thread.