Page 1 of 1
[Solved] love.graphics.printf return number of lines?
Posted: Fri May 10, 2013 9:40 am
by Germanunkol
I don't understand why love.graphics.printf doesn't return anything? I think it would be very useful if it returned the number of lines printed...?
Any thoughts on this? Developers, would this be hard to implement?
Re: love.graphics.printf return number of lines?
Posted: Sun May 12, 2013 6:59 pm
by XOdysseusX
The number of lines printed? You mean in the console?
If so, it wouldn't be in love.graphics.
It seems like an interesting idea, though I don't know why you would need it, the value would increase by one every time you use the print() command, which can be implemented yourself easily.
Ofcourse, shortcuts are always nice.
Re: love.graphics.printf return number of lines?
Posted: Mon May 13, 2013 3:59 am
by Santos
Is
Font:getWrap what you're looking for?
Re: love.graphics.printf return number of lines?
Posted: Wed Jul 10, 2013 12:17 am
by Germanunkol
Sorry for the necro post, but yes, that was what I was looking for - thanks!
However, I don't understand why this isn't also returned by love.graphics.printf. This will mean the processing has to be done twice... and string manipulation isn't the quickest.
@ XOdysseus:
I need it for a lot of reasons. For example: When you use love.graphics.printf to output a chat box, then one line of text a user inputs might be more than one line of text in the chat box. If the next player also sends something, and that new text should be displayed underneath the old one, then I need to know how much space the old text used up, vertically, so that I can call the next printf function to place text below that.
Now I can use Font:getWrap and Font:getHeight() to know the number of pixels, so that works.
Re: love.graphics.printf return number of lines?
Posted: Wed Jul 10, 2013 12:38 am
by davisdude
You could also do
Code: Select all
font = love.graphics.newFont('font.ttf')
love.graphics.setFont(font)
string = 'lol'
width = font:getWidth( string )
And then apply math. Of course the other also works (and is probably easier, too...)
Re: love.graphics.printf return number of lines?
Posted: Wed Jul 10, 2013 12:41 am
by slime
Germanunkol wrote:This will mean the processing has to be done twice... and string manipulation isn't the quickest.
Most strings won't change as often as they're drawn. You only need to determine the number of lines a string will take up when the string changes or the textbox size changes.
Re: love.graphics.printf return number of lines?
Posted: Wed Jul 10, 2013 9:38 am
by Germanunkol
slime wrote:Germanunkol wrote:This will mean the processing has to be done twice... and string manipulation isn't the quickest.
Most strings won't change as often as they're drawn. You only need to determine the number of lines a string will take up when the string changes or the textbox size changes.
You're right, of course, and I'm not really complaining. All I'm saying is that love.graphics.printf _could_ return the number of lines which would make sense to me and would be a nice design.
But with the finding of font:getWrap the problem is solved. I also understand why they implemented this function, this way you can check how much space a text would take up before actually printing it.
Thanks for all the replies & help!