Time for action - building the GameObject class part 2

  1. Add the updateAnimation() helper method to the GameObject class:
    #region Helper Methods
    private void updateAnimation(GameTime gameTime)
    {
    if (animations.ContainsKey(currentAnimation))
    {
    if (animations[currentAnimation].FinishedPlaying)
    {
    PlayAnimation(animations[currentAnimation]. NextAnimation);
    }
    else
    {
    animations[currentAnimation].Update(gameTime);
    }
    }
    }
    #endregion
    
  2. Add a new region called "Public Methods" to the GameObject class:
    #region Public Methods
    #endregion
    
  3. Inside the Public Methods region, add the PlayAnimation() method:
    public void PlayAnimation(string name)
    {
    if (!(name==null) && animations.ContainsKey(name))
    {
    currentAnimation = name;
    animations[name].Play();
    }
    }
    
  4. Still in the ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.