Is there any way in advance to get the width of text to be printed using love.graphics.print before printing it? Or even after.
Cheers,
Paul
Get width of text printed using print
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 11
- Joined: Fri May 17, 2013 7:40 am
Re: Get width of text printed using print
Yes. You can figure out the width of the font, Then multiply that by the length of the string. This works best if your font is monospaced
To get the length of a string you can use #.
If you're trying to center the text or something similar, Perhaps you could look into printf.
To get the length of a string you can use #.
Code: Select all
string = "whatever"
string_length = #string
Re: Get width of text printed using print
font:getWidth usage:
Code: Select all
local font = love.graphics.getFont()
local width =font:getWidth("Foobar and some other words too") --gets the width of the argument in pixels for this font
-
- Prole
- Posts: 11
- Joined: Fri May 17, 2013 7:40 am
Re: Get width of text printed using print
You guys. <3. :getWidth() will do very nicely.
Thanks!
Thanks!
Who is online
Users browsing this forum: Azzla and 4 guests