How to resize an image if I am using a source and destination rectangle.


I am displaying a single image of a single number on the screen. My draw statement is given below. I want the image to get larger over a certain period of time. This will give the impression to the user that the image is growing larger and larger until a certain size has been reached. So my question is how can I scale the image to get larger and smaller considering the Draw statement I am using below.

spriteBatch.Draw(currentScore.OneNumber, currentScore.destPosition, currentScore.destPosition, Color.White);

SpriteBatch.Draw has a whole pile of overloads. There’s two that will scale the texture that is supplied…

There’s one (two, actually) that take a scale factor, either as a float (uniform axis scaling) or a Vector2 (for independent axis scaling). This overload takes a Vector2 origin, relative to the texture’s top-left, that is the origin for the transform to be applied.

Alternatively, there’s an overload that takes a source rectangle (all or a portion of the texture you want to draw) and a destination rectangle (the rectangle the specified portion of the texture should be drawn to). If the destination rectangle isn’t the same size as the source (either larger or smaller), the resulting image will be scaled to fit.

Check these out and if you have any more questions, or trouble with implementation, post back here :slight_smile:


I figured it out, thanks.

1 Like