1
\$\begingroup\$

How do i draw a texture2D in a specific area (rectangle) where the texture is bigger than the rectangle, and i dont want to draw outside the rectangle. So that means i want to cut the texture so it fits the rectangle area (if its too big).

For example if the rectangle area is 200 x 100 and my texture (the smiley) is 200 x 150 then i want to cut the last 50 off so it only draws 200 x 100

Example

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can use SpriteBatch.Draw(Texture2D, Rectangle, Nullable<Rectangle>, Color)

public void Draw (
         Texture2D texture,
         Rectangle destinationRectangle,
         Nullable<Rectangle> sourceRectangle,
         Color color
)

compare the size of the destinationRectangle and the size of the texture. Next you need to take the lowest values ​​and using them in sourceRectangle

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .