Hey guys. quick question. Is it possible to center text displayed with love.graphics.print? I know the "formula" to center stuff to the screen but for that i'd need something that would return the width of said thing. And i've looked through the wiki and didn't find any function or something that would do that. Perhaps there is one, But i'm just blind/stupid.
Thanks in advance.
[SOLVED]Centering text to screen
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Centering text to screen
You could use a fixed width font which would allow you to calculate the width easily
Re: Centering text to screen
Don't know if this is the formula you referring but can't you use printf instead of print? Only need to know the screen width (so usually a fixed var) and not always getting object/text sizeveethree wrote:Hey guys. quick question. Is it possible to center text displayed with love.graphics.print? I know the "formula" to center stuff to the screen but for that i'd need something that would return the width of said thing. And i've looked through the wiki and didn't find any function or something that would do that. Perhaps there is one, But i'm just blind/stupid.
Thanks in advance.
w = love.graphics.getWidth()
love.graphics.printf(text,0,0,w)
Re: Centering text to screen
I completely forgot about printf, Haven't fully tested it, But it appears to work if i do what you did and set the alignment to "center". Thankscoffee wrote:Don't know if this is the formula you referring but can't you use printf instead of print? Only need to know the screen width (so usually a fixed var) and not always getting object/text sizeveethree wrote:Hey guys. quick question. Is it possible to center text displayed with love.graphics.print? I know the "formula" to center stuff to the screen but for that i'd need something that would return the width of said thing. And i've looked through the wiki and didn't find any function or something that would do that. Perhaps there is one, But i'm just blind/stupid.
Thanks in advance.
w = love.graphics.getWidth()
love.graphics.printf(text,0,0,w)
Oh and the formula i was referring to is setting the X position of an object to the center then subtracting half of it's width. (not sure if that makes sense, just look at the code. lol)
something like this:
Code: Select all
w = love.graphics.getWidth()
love.graphics.rectangle("fill", w/2 - 50, 10, 100, 100)
Who is online
Users browsing this forum: Google [Bot], Nikki and 5 guests