SFML community forums

Help => Graphics => Topic started by: Wander on January 02, 2011, 08:22:34 pm

Title: [Solved] Trouble Centering Text
Post by: Wander on January 02, 2011, 08:22:34 pm
I'm trying to center my text inside of box, but I'm having some trouble doing so.

Does anyone know what is wrong with this code?
x,y is the corner in the top-left.
x2,y2 is the corner in the bottom-right.
x = left
y = top
x2 = right
y2 = bottom

Code: [Select]
sf::FloatRect StringRect( sf_text.GetRect() );
canvas.SetPosition(x, y);
sf_text.SetPosition(x, y);
sf_text.Move(((x2-x)/2)-StringRect.GetWidth()/2,((y2-y)/2)-StringRect.GetHeight()/2);