Monogame Animated Sprite [ FULL | 2027 ]

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); }

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

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

Here’s a self-contained, ready-to-use piece for .

if (_elapsedTime >= _timePerFrame) { _currentFrame++; _elapsedTime -= _timePerFrame; public void Draw(SpriteBatch spriteBatch

public void Play() => IsPlaying = true; public void Pause() => IsPlaying = false; public void Stop() { IsPlaying = false; _currentFrame = 0; _elapsedTime = 0; } public void Restart() { _currentFrame = 0; _elapsedTime = 0; IsPlaying = true; } } using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; public class Game1 : Game { private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; private AnimatedSprite _animatedSprite; private Texture2D _spritesheet;

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

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