Monogame Animated Sprite _top_ Link
// Example controls var kstate = Keyboard.GetState(); if (kstate.IsKeyDown(Keys.Space) && !_animatedSprite.IsPlaying) _animatedSprite.Play(); if (kstate.IsKeyDown(Keys.P)) _animatedSprite.Pause(); if (kstate.IsKeyDown(Keys.R)) _animatedSprite.Restart();
if (_currentFrame >= _frames.Count) { if (_looping) _currentFrame = 0; else { _currentFrame = _frames.Count - 1; IsPlaying = false; } } } } monogame animated sprite
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); } // Example controls var kstate = Keyboard
public bool IsPlaying { get; private set; } if (kstate.IsKeyDown(Keys.P)) _animatedSprite.Pause()
if (_elapsedTime >= _timePerFrame) { _currentFrame++; _elapsedTime -= _timePerFrame;