KnightHawk
KnightHawk

Reputation: 1

How to crop text in monogame?

I'm making a game in monogame that uses fake windows as a puzzle element. I'm able to resize the windows, and I figured out how to crop images at the edges of the window, but I can't figure out how to crop text when you resize a window.

I can't just remove each letter when they go behind the border, because:

  1. the text is drawn after the border, and
  2. the letters are wider than the border. I'm using the default SpriteFont class and _spriteBatch.DrawString method for my text.

Basically, I want the following code to crop the text in some way

SpriteFont font = Content.Load<SpriteFont> ("font file");
_spriteBatch.Begin();
_spriteBatch.DrawString(
    font,
    "Text here",
    Vector2.Zero,
    Color.White
    );
_spriteBatch.End();

I looked through the documentation, but couldn't find any overloads that let you crop text. Please help.

Upvotes: 0

Views: 42

Answers (1)

James
James

Reputation: 2058

There is a property on the sprite batch for a scissor rectangle, use it to specify the area which it is allowed to draw within.

Upvotes: 0

Related Questions