# Drawing a sprite in a rect.

This topic is 3520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I've recently switched from using textured quads for my 2d game to using sprites, surprisingly though I did not find a place for Destination Rect in the sprite's Draw call, and I happen to need that feature. Basically is there any way to draw a sprite in a specified rect. P.S I know that you can probably use some sort of an equation to figure out the scaling and the translate factors that would make it the size of a given rect, but is there a more elegant solution? Thanks

##### Share on other sites

[Edited by - Alatar on June 4, 2009 1:08:29 AM]

##### Share on other sites
I think it worked because you used the same size image. What I'm guessing is that the scale matrix will scale the image from the center outwards, meaning that it would scale in the + and - x directions. So even if I put the pos as the top coordinates of the rect, the scaling will offset it. The only way I think this might work is if I set the center to the top left corner of image, set the position as the top left corner of the dest rect, then come up with an equation that would give me a scale factor depending how far the right edge of the image is from the right edge of the dest rect. But this seems a little too much, all this work just to draw a sprite in one spot, and I plan to have lots (of animated) sprites all over the place, I might as well stick with textured quads... Anyways is this the only way? I can't believe DX guys left out such an obvious function.

##### Share on other sites

[Edited by - Alatar on June 4, 2009 1:32:39 AM]

##### Share on other sites
How would I downscale a sprite without a destination rect? What I'm basically saying is lets say I have an image that's like 1024x800 and I want to disply it as a small 306x200 model on screen, without a dest rect I would have to basically do all the things I said in the last post.

##### Share on other sites
Right, sorry I missed that. Good luck finding a solution!

##### Share on other sites
[bump] So is there no other way?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634146
• Total Posts
3015774
×