Page 1 of 1
love.graphics.printf 'ing a string with multiple spaces
Posted: Sat Aug 18, 2012 9:57 pm
by chute
Hi guys,
I think this one will be quick. When I use the following code:
Code: Select all
text = "Test Text" --the extra spaces here are intentional
love.graphics.printf(text, 10, 10, 100, "center")
it prints "Test Text" no matter how many spaces are in between the two words. love.graphics.print doesn't have this problem, so I assume it has something to do with the formatting code of printf.
Is there any way to force multiple spaces through printf?
Thanks!
Re: love.graphics.printf 'ing a string with multiple spaces
Posted: Sat Aug 18, 2012 11:37 pm
by kexisse
It's most likely that "center" alignment is trying to justify the text, making it spread out between your text area of size 100px.
Re: love.graphics.printf 'ing a string with multiple spaces
Posted: Sun Aug 19, 2012 12:48 am
by Roland_Yonaba
Yeah, definitely.
Maybe you can hardcode a text centering function. Assuming a default font width, and a number limit:
Code: Select all
function center(text,number_limit)
return (number_limit/2)-(text:len()*default_font_width)/2
end
function love.draw()
text = "whatever"
love.graphics.print(text,center(text),y)
end
Re: love.graphics.printf 'ing a string with multiple spaces
Posted: Sun Aug 19, 2012 1:27 am
by Boolsheet
You're right, the code checks for the normal space. You can use one of
the other space characters that unicode provides and it won't break into a newline.
Code: Select all
NBSP = "\194\160"
text = "Test".. NBSP:rep(25).. "Text"
You can of course use UTF-8 encoding with your text editor and write the character directly, just don't forget to save without the BOM.
Re: love.graphics.printf 'ing a string with multiple spaces
Posted: Sun Aug 19, 2012 1:49 am
by Roland_Yonaba
Boolsheet wrote:You're right, the code checks for the normal space. You can use one of
the other space characters that unicode provides and it won't break into a newline.
Code: Select all
NBSP = "\194\160"
text = "Test".. NBSP:rep(25).. "Text"
You can of course use UTF-8 encoding with your text editor and write the character directly, just don't forget to save without the BOM.
Seems it doesn't works... I just get the word "Text" printed. -_-
Re: love.graphics.printf 'ing a string with multiple spaces
Posted: Sun Aug 19, 2012 2:24 am
by Boolsheet
Roland_Yonaba wrote:Seems it doesn't works... I just get the word "Text" printed. -_-
Move it some more to the right?
Re: love.graphics.printf 'ing a string with multiple spaces
Posted: Sun Aug 19, 2012 2:33 am
by Roland_Yonaba
Gosh...
Sankyu for the tip, BTW!
Re: love.graphics.printf 'ing a string with multiple spaces
Posted: Sun Aug 19, 2012 8:04 pm
by chute
Boolsheet wrote:You're right, the code checks for the normal space. You can use one of
the other space characters that unicode provides and it won't break into a newline.
Code: Select all
NBSP = "\194\160"
text = "Test".. NBSP:rep(25).. "Text"
You can of course use UTF-8 encoding with your text editor and write the character directly, just don't forget to save without the BOM.
This helped. I forgot to mention it was an image font. I added \194\160 to the end of the image font and alternated the two spaces (like "Test \194\160 \194\160 \194\160 Text".
Thanks!