Time for action – building the GameObject class – part 2
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
Add a new region called "Public Methods" to the GameObject class:
#region Public Methods #endregion
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(); } }
Still in the Public Methods region, add the
Update()
method:public virtual void Update(GameTime gameTime) { if (!enabled) return; float...