Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 8 down vote accepted

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.

share|improve this answer
great, that is the answer, it works perfectly. thanks! – pablopp83 May 24 '13 at 18:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.