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 .
chute
Prole
Posts: 18 Joined: Sat Sep 17, 2011 6:49 pm
Post
by chute » Sat Aug 18, 2012 9:57 pm
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!
kexisse
Citizen
Posts: 56 Joined: Wed Jun 13, 2012 2:52 pm
Post
by kexisse » Sat Aug 18, 2012 11:37 pm
It's most likely that "center" alignment is trying to justify the text, making it spread out between your text area of size 100px.
Roland_Yonaba
Inner party member
Posts: 1563 Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:
Post
by Roland_Yonaba » Sun Aug 19, 2012 12:48 am
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
Boolsheet
Inner party member
Posts: 780 Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland
Post
by Boolsheet » Sun Aug 19, 2012 1:27 am
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.
Shallow indentations.
Roland_Yonaba
Inner party member
Posts: 1563 Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:
Post
by Roland_Yonaba » Sun Aug 19, 2012 1:49 am
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. -_-
Attachments
main.lua
(144 Bytes) Downloaded 156 times
Boolsheet
Inner party member
Posts: 780 Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland
Post
by Boolsheet » Sun Aug 19, 2012 2:24 am
Roland_Yonaba wrote: Seems it doesn't works... I just get the word "Text" printed. -_-
Move it some more to the right?
Shallow indentations.
Roland_Yonaba
Inner party member
Posts: 1563 Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:
Post
by Roland_Yonaba » Sun Aug 19, 2012 2:33 am
Gosh...
Sankyu for the tip, BTW!
chute
Prole
Posts: 18 Joined: Sat Sep 17, 2011 6:49 pm
Post
by chute » Sun Aug 19, 2012 8:04 pm
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!
Users browsing this forum: Bing [Bot] , Google [Bot] , Semrush [Bot] and 3 guests