public bool IsPlaying { get; private set; }
protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); // Load a spritesheet: each frame is 64x64, 8 frames total (8 columns, 1 row) _spritesheet = Content.Load<Texture2D>("player_run"); _animatedSprite = new AnimatedSprite(_spritesheet, 64, 64, 12.0, true); } monogame animated sprite
Here’s a self-contained, ready-to-use piece for . public bool IsPlaying { get; private set; }
if (_currentFrame >= _frames.Count) { if (_looping) _currentFrame = 0; else { _currentFrame = _frames.Count - 1; IsPlaying = false; } } } } public bool IsPlaying { get
_animatedSprite.Update(gameTime); base.Update(gameTime); }
// 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)); } }
protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit();