Page 1 of 1

Anyone knows what's wrong with these button texts?

Posted: Tue Feb 22, 2022 5:35 pm
by WAWAWA
I am very confused, as I have never created buttons before. I don't understand this, the text goes off when I do the following equation:

Code: Select all

love.graphics.print(
	text, font,
	(w/2) - #text,y
)
text = "Play Game"
font = Normal font
w = width of the box
h = height of the box
x = x pos of the box
y = y pos of the box

Re: Anyone knows what's wrong with these button texts?

Posted: Tue Feb 22, 2022 6:03 pm
by dusoft
Use printf
See also viewtopic.php?t=10653

Re: Anyone knows what's wrong with these button texts?

Posted: Tue Feb 22, 2022 6:28 pm
by BrotSagtMist
May you give screenshot or actual code to what you get wrong?
Edit:
Actually i have a template for buttons, this is how i do them usually:
main.lua.love
(493 Bytes) Downloaded 91 times

Re: Anyone knows what's wrong with these button texts?

Posted: Wed Feb 23, 2022 8:40 pm
by bizziboi
I am guessing your problem is that you subtract the number of characters in the the label in pixels.

You want to get the width of the rendered string and divide that by two instead?