Page 1 of 1

Getting the size of text / font

Posted: Mon Nov 14, 2011 7:06 pm
by Dilli
Hey guys,
first post - was mainly lurking the last weeks ;)
At the moment I'm trying to create some game menus from scratch.
There are several buttons which will be filled with text:

Is there any way to determine / calculate the size of the drawn text?

I already searched the forums and wiki but didn't find anything, but as there is an maximum
width option via love.graphics.printf I'm optimistic that this is somehow possible :)

Re: Getting the size of text / font

Posted: Mon Nov 14, 2011 7:19 pm
by Robin

Re: Getting the size of text / font

Posted: Mon Nov 14, 2011 7:21 pm
by tentus
Hello, and welcome! Since Robin answered your question, I have a question for you: is your avatar Gon? I love that series!

Re: Getting the size of text / font

Posted: Mon Nov 14, 2011 7:47 pm
by Dilli
Thank you very much. Don't know why I didn't find that :|
tentus wrote:Hello, and welcome! Since Robin answered your question, I have a question for you: is your avatar Gon? I love that series!
Indeed, my first and still favourite manga. Most people know him from his starring in Tekken though ;)

Re: Getting the size of text / font

Posted: Sun Dec 25, 2011 6:54 pm
by zipperipper
What about for LÖVE's default font? How would one call :width(string) on LÖVE's default font?
or do I HAVE to create my own? D:
I need a font to use for a console, I've been trying to get a solid courier new but didn't have much luck :U

Re: Getting the size of text / font

Posted: Sun Dec 25, 2011 8:16 pm
by Robin
Can't you use love.graphics.getFont():getWidth("blah")? Or doesn't that work?

Re: Getting the size of text / font

Posted: Sun Dec 25, 2011 8:42 pm
by zipperipper
No it doesnt, but dont worry, i got it. :3
it says on http://love2d.org/wiki/Tutorial:Fonts_a ... g_an_image that you can use

Code: Select all

font = love.graphics.newFont(15)
to get the default font.