Drawing custom sprites onto a button in monogame

269 views Asked by At

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.

1

There are 1 answers

0
Max Play On

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.