Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] Trouble Centering Text  (Read 1617 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] Trouble Centering Text
« 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);
-Wander

 

anything