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.