3
\$\begingroup\$

i'm drawing a text using a spritefont and the draw.string function of the spritebatch object. in some point, i need to augment the size of the text, so i use a variable to scale it. all this is working fine, but i need to find the center of the text to use as origin to make the effect look like i want. how can i find that center point of a text? when i use textures its easy because i just take half the texture width and height, but with a spritefont, i dont have any idea of how to proceed. Thanks.

\$\endgroup\$

1 Answer 1

8
\$\begingroup\$

You need to use SpriteFont.MeasureString.

Vector2 textSize = mySpriteFont.MeasureString("Hello World");
Vector2 center = textSize / 2;

The x component of textSize represents the width of the measured string while the y component represents the height.

\$\endgroup\$
1
  • \$\begingroup\$ great, that is the answer, it works perfectly. thanks! \$\endgroup\$
    – pablopp83
    May 24, 2013 at 18:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .