I'm using monogame. I want to overlay Text onto one of my button images, but I want to use the image way of drawing;
spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White);
so that I can control how the text is handled inside the bounds of the button image rectangle, like trim excess.
Is there a way to draw strings using the fontsprite, without using the spriteBatch.DrawString
method, or is there more to this method that I haven't learned yet? It just seems limiting from its input parameters.
You can use
Font.MeasureString
to get the width and height of a string as aVector2
. You can subtract half of it from the center position of aRectangle
and you get your centered text.