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?
[Solved] love.graphics.printf return number of lines?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
[Solved] love.graphics.printf return number of lines?
Last edited by Germanunkol on Wed Jul 10, 2013 9:39 am, edited 1 time in total.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
-
- Prole
- Posts: 11
- Joined: Fri Apr 26, 2013 3:32 pm
Re: love.graphics.printf return number of lines?
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.
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?
Is Font:getWrap what you're looking for?
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: love.graphics.printf return number of lines?
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.
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.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Re: love.graphics.printf return number of lines?
You could also do
And then apply math. Of course the other also works (and is probably easier, too...)
Code: Select all
font = love.graphics.newFont('font.ttf')
love.graphics.setFont(font)
string = 'lol'
width = font:getWidth( string )
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- slime
- Solid Snayke
- Posts: 3170
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: love.graphics.printf return number of lines?
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.Germanunkol wrote:This will mean the processing has to be done twice... and string manipulation isn't the quickest.
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: love.graphics.printf return number of lines?
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.slime wrote: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.Germanunkol wrote:This will mean the processing has to be done twice... and string manipulation isn't the quickest.
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!
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest