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 ...
Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.