Animated Sprite | Monogame

public void Draw(SpriteBatch spriteBatch, Vector2 position, SpriteEffects effects = SpriteEffects.None) { spriteBatch.Draw(_texture, position, _frames[_currentFrame], Color.White, 0f, Vector2.Zero, 1f, effects, 0f); }

protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit();

if (_currentFrame >= _frames.Count) { if (_looping) _currentFrame = 0; else { _currentFrame = _frames.Count - 1; IsPlaying = false; } } } } monogame animated sprite

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

public bool IsPlaying { get; private set; } public void Draw(SpriteBatch spriteBatch

public void Update(GameTime gameTime) { if (!IsPlaying) return;

// 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)); } } if (_currentFrame &gt

_elapsedTime += gameTime.ElapsedGameTime.TotalSeconds;