O'Reilly logo

XNA 4.0 Game Development by Example Beginner's Guide by Kurt Jaegers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required