Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.