Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.