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.