Advertisement
Yesideez

Centre text function for TIC-80 in Lua

Jun 21st, 2022 (edited)
1,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.67 KB | None | 0 0
  1. ------------------------------------------------
  2. -- printText v1.00  by Zeb/SLP (21-Jun-2022)  --
  3. --                                            --
  4. -- Purpose: Centre text on the screen         --
  5. --                                            --
  6. -- pen: color (default=12)                    --
  7. -- align: 0=left, 1=centre (default), 2=right --
  8. ------------------------------------------------
  9. function printText(txt,yPos,pen,align)
  10.  if (align==nil) then align=1 end
  11.  if (pen==nil) then pen=12 end
  12.  local len=string.len(txt)-1
  13.  local xPos=0
  14.  if (align==1) then
  15.   xPos=120-((len*6)/2)
  16.  elseif (align==2) then
  17.   xPos=240-(len*6)
  18.  end
  19.  print(txt,xPos,yPos,pen)
  20. end --printText
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement