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.


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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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