0

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.

Servy
  • 202,030
  • 26
  • 332
  • 449

1 Answers1

1

You can use Font.MeasureString to get the width and height of a string as a Vector2. You can subtract half of it from the center position of a Rectangle and you get your centered text.

Max Play
  • 3,717
  • 1
  • 22
  • 39