# How can I animate the stretching of a sprite over time?

My goal is to find the function to stretch a sprite like my example below, and then get it to animate during a certain time. It is like an interpolation, where the starting point is the original image, and the final point is the stretched image. Any idea?

Here is an example, hope it is clear.

• Your question is a combination of a few simple techniques. Scaling a sprite and changing a value over time. You may find it useful in the future to break apart your problem into smaller problems, that are more generic and easily searchable. – MichaelHouse Aug 29 '13 at 18:42
• Thanks a lot. I found very useful your links and your suggestion. – Francesco Bonizzi Aug 29 '13 at 19:16

The SpriteBatch class's Draw method has an overload that allows you to specify a scale factor. Thus, to render a sprite in a stretched frame, do something like:

// Scale the sprite 50% along X (like in your example).
var scale = new Vector2(0.5f, 1.0f);

// Draw the sprite with that scale.
spriteBatch.Draw(
texture,
position,
null,
Color.White,
0.0f,
Vector2.Zero,
scale,
SpriteEffects.None,
0
);


To achieve an animation of this effect, store your scale factor somewhere (a member in your Game class would be simple to start with), and update it over time in your game's Update method. The Update method gives you a GameTime object containing the elapsed time since the last update. Every update, adjust your scaling factor by the amount you want to scale per second using the TotalSeconds member of the elapsed time span object.