As reward of your 5-star review, here my lib to compute the size of a text
Well, this is not really my lib cause I found the trick somewhere in this forum.
Unfortunately I can’t remember who is the real author
----------------------------------------------------------------------------------------- -- -- textHelper.lua -- ----------------------------------------------------------------------------------------- local module = {} module.getTextDimension = function(options) local txt=options.text options.text=" " local tempRow = display.newText(options) local rowHeight = tempRow.height options.text=txt local tempText = display.newText(options) local h=tempText.height local w=tempText.width local numRows = math.floor(h/rowHeight) tempText:removeSelf() tempRow:removeSelf() -- return a table with the number of rows & pixel height return {numRows=numRows, height=h, width = w} end return module
here an example of how you should used :
local options = { parent = group, text = text, fontSize = fontSizeText, font = self.fontText, align = center, x = screen.width \* 0.20, y = 0, width = screen.width \* 0.60 } local textInfo = textHelper.getTextRowsHeight(options) local tb = display.newText( options ) tb:setFillColor(unpack(self.white)) tb.anchorX = 0 tb.anchorY = 0 tb.y = screen.height / 2 - textInfo.height \* 1.25