Getting the size of text / font

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Dilli
Prole
Posts: 5
Joined: Sat Oct 15, 2011 10:11 am

Getting the size of text / font

Post 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 :)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Getting the size of text / font

Post by Robin »

Help us help you: attach a .love.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Getting the size of text / font

Post by tentus »

Hello, and welcome! Since Robin answered your question, I have a question for you: is your avatar Gon? I love that series!
Kurosuke needs beta testers
User avatar
Dilli
Prole
Posts: 5
Joined: Sat Oct 15, 2011 10:11 am

Re: Getting the size of text / font

Post 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 ;)
User avatar
zipperipper
Prole
Posts: 45
Joined: Thu Jan 14, 2010 7:59 pm
Location: UK

Re: Getting the size of text / font

Post 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
Error 404, consciousness not found.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Getting the size of text / font

Post by Robin »

Can't you use love.graphics.getFont():getWidth("blah")? Or doesn't that work?
Help us help you: attach a .love.
User avatar
zipperipper
Prole
Posts: 45
Joined: Thu Jan 14, 2010 7:59 pm
Location: UK

Re: Getting the size of text / font

Post 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.
Error 404, consciousness not found.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests