Scaling sprite


I’m playing around and noticed that my 128x128 pixel sprites are a bit too large for the current resolution so I googled around and noticed that the spritebatch Draw function takes in a few extra parameters.
This is my code:

            new Rectangle(512, 512, 64, 64),
            new Rectangle(512, 512, 128, 128),

        _spriteBatch.Draw(windowLeft, new Rectangle(800, 800, 128, 128), Color.White);

The last code part works just fine but the previous code does not. I thought it would scale but it does not even seem to be able to draw the sprite if I use an extra parameter to Draw. What am I doing wrong?

//The method of Draw I am trying to use after googling:
public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color)

sourceRectangle is defined in texel units, basically coordinates on the texture of the sprite itself, not screen coordinates(which I assume the 512,512 coordinate is).

If you’re drawing the entire texture, there’s no reason to use sourceRectangle, and you can just shrink the destination rectangle to shrink it.

_spriteBatch.Draw(windowLeft, new Rectangle(800, 800, 64, 64), Color.White);

This should draw the sprite scaled down.

Thank you!

I had no idea it was “texels” and googling it makes me still a bit clueless :P. What you posted worked great though!

Texels are a generalization of pixels. In 2D textures(most of the things you’ll be working with), they pretty much directly map to the pixels of the image.

What’s important to you right now is that sourceRectangle defines which pixels on the texture you’re drawing get used to fill the destinationRectangle on the render target.