I guess I’ve found the issue. I use code Multiline text with width in pixel, but slightly modify
function autoWrappedText(text, font, size, color, width, linesTotal)
if text == '' then return false end
font = font or native.systemFont
size = tonumber(size) or 12
color = color or {255, 255, 255}
width = width or display.stageWidth
local result = display.newGroup()
local currentLine = ''
local currentLineLength = 0
local lineCount = 0
local left = 0
for line in string.gmatch(text, "[^\n]+") do
for word, spacer in string.gmatch(line, "([^%s%-]+)([%s%-]\*)") do
local tempLine = currentLine..word..spacer
local tempDisplayLine = display.newText(tempLine, 0, 0, font, size)
if tempDisplayLine.width \<= width then
currentLine = tempLine
currentLineLength = tempDisplayLine.width
else
local newDisplayLine = display.newText(currentLine, 0, (size \* 1.3) \* (lineCount - 1), font, size)
newDisplayLine:setTextColor(color[1], color[2], color[3])
result:insert(newDisplayLine)
lineCount = lineCount + 1
if string.len(word) \<= width then
currentLine = word..spacer
currentLineLength = string.len(word)
else
local newDisplayLine = display.newText(word, 0, (size \* 1.3) \* (lineCount - 1), font, size)
newDisplayLine:setTextColor(color[1], color[2], color[3])
result:insert(newDisplayLine)
lineCount = lineCount + 1
currentLine = ''
currentLineLength = 0
end
end
tempDisplayLine:removeSelf()
tempDisplayLine = nil
end
local newDisplayLine = display.newText(currentLine, 0, (size \* 1.3) \* (lineCount - 1), font, size)
newDisplayLine:setTextColor(color[1], color[2], color[3])
result:insert(newDisplayLine)
lineCount = lineCount + 1
currentLine = ''
currentLineLength = 0
end
--
-- new code
--
currentLine = '' -- works with currentLine = ' '
for i = lineCount+1, linesTotal do
local newDisplayLine = display.newText(currentLine, 0, (size \* 1.3) \* (i-1), font, size)
newDisplayLine:setTextColor(color[1], color[2], color[3], color[4])
result:insert(newDisplayLine)
end
result:setReferencePoint(display.CenterReferencePoint)
return result
end
linesTotal - parameter which determine how many text lines will be created, not depending on the input text, to have possibility to change the text later.
so using this code like this:
local test = "Lorem ipsum Lorem ipsum"
local testAutoWrapText = autoWrappedText( test, "Arial", 42, {0,0,0}, 140, 5 )
testAutoWrapText.x = 120
testAutoWrapText.y = 200
It shows text in different position in Corona Simulator and in iPhone Simulator and on Device. It looks like display.newText with empty string works different in Corona Simulator and on Device. [import]uid: 7301 topic_id: 630 reply_id: 18109[/import]