Log In  
Follow
dandiemer

Web developer with a love for games

[ :: Read More :: ]

I just submitted this to the Wiki, but figured it might be more visible here.

Here is how I handled text centering in some recent code. Any improvements are welcome.

textlabel="this is some cool text!!!"

function hcenter(s)
    -- string length times the 
    -- pixels in a char's width
    -- cut in half and rounded down
    return 64-flr((#s*4)/2)
end

function vcenter(s)
    -- string char's height
    -- cut in half and rounded down
    return 64-flr(5/2)
end

function _draw()
    rectfill(0,0,128,128,0)
    print(textlabel,hcenter(textlabel),vcenter(textlabel),8)
end
P#21924 2016-05-31 14:50 ( Edited 2016-05-31 22:42)

Follow Lexaloffle:          
Generated 2024-04-20 11:00:47 | 0.071s | Q:5