I think I'm missing something in this function. Test code:
Code: Select all
function love.load()
font = love.graphics.newFont(12)
love.graphics.setFont(font)
lines = 0
text = ""
timePassed = 0
end
function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.printf(text, 0, 0, 1000, "left")
end
function love.update(dt)
timePassed = timePassed + dt
if timePassed > 1 then
timePassed = timePassed - 1
lines = lines + 1
if #text > 0 then
text = text .. "\n"
end
text = text .. 'a'
local _, wrapLines = font:getWrap(text, 1000)
print('Lines', lines, 'Wrap lines', wrapLines, _)
end
end
Using the 0.7 beta on Windows 7.
The text takes up more and more lines, but the lines variable stays 1, while width increases. Has the function changed since this post? I couldn't find it in the wiki.
Edit
Okay so I went and looked at the C source, like I probably should have originally. It appears getWrap is intended to only find the wrap for a piece of text without newlines in it, hence my weird results. I was thrown off by assuming it was intended to measure the height of any string you could hand to love.graphics.print. I've rewritten my font rendering to bear this in mind and it works perfectly now.
Should I edit the documentation to add this method, with a quick explanation of this to ensure other people don't trip over this problem in future?