I think I'm missing something in this function. Test code:
Code: Select all
font = love.graphics.newFont(12)
lines = 0
text = ""
timePassed = 0
love.graphics.setColor(255, 255, 255)
love.graphics.printf(text, 0, 0, 1000, "left")
timePassed = timePassed + dt
if timePassed > 1 then
timePassed = timePassed - 1
lines = lines + 1
if #text > 0 then
text = text .. "\n"
text = text .. 'a'
local _, wrapLines = font:getWrap(text, 1000)
print('Lines', lines, 'Wrap lines', wrapLines, _)
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.
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?