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 |
