Animated Sprite — Monogame

public Game1() { _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; }

_elapsedTime += gameTime.ElapsedGameTime.TotalSeconds; monogame animated sprite

public AnimatedSprite(Texture2D texture, int frameWidth, int frameHeight, double framesPerSecond, bool looping = true) { _texture = texture; _frames = new List<Rectangle>(); _currentFrame = 0; _timePerFrame = 1.0 / framesPerSecond; _elapsedTime = 0; _looping = looping; IsPlaying = true; Content.RootDirectory = "Content"

// Split texture into frames (assumes frames in a single row) int columns = texture.Width / frameWidth; for (int i = 0; i < columns; i++) { _frames.Add(new Rectangle(i * frameWidth, 0, frameWidth, frameHeight)); } } IsMouseVisible = true