Animation.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Animation.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. using System;
  10. using Microsoft.Xna.Framework.Graphics;
  11. namespace Platformer
  12. {
  13. /// <summary>
  14. /// Represents an animated texture.
  15. /// </summary>
  16. /// <remarks>
  17. /// Currently, this class assumes that each frame of animation is
  18. /// as wide as each animation is tall. The number of frames in the
  19. /// animation are inferred from this.
  20. /// </remarks>
  21. class Animation
  22. {
  23. /// <summary>
  24. /// All frames in the animation arranged horizontally.
  25. /// </summary>
  26. public Texture2D Texture
  27. {
  28. get { return texture; }
  29. }
  30. Texture2D texture;
  31. /// <summary>
  32. /// Duration of time to show each frame.
  33. /// </summary>
  34. public float FrameTime
  35. {
  36. get { return frameTime; }
  37. }
  38. float frameTime;
  39. /// <summary>
  40. /// When the end of the animation is reached, should it
  41. /// continue playing from the beginning?
  42. /// </summary>
  43. public bool IsLooping
  44. {
  45. get { return isLooping; }
  46. }
  47. bool isLooping;
  48. /// <summary>
  49. /// Gets the number of frames in the animation.
  50. /// </summary>
  51. public int FrameCount
  52. {
  53. get { return Texture.Width / FrameWidth; }
  54. }
  55. /// <summary>
  56. /// Gets the width of a frame in the animation.
  57. /// </summary>
  58. public int FrameWidth
  59. {
  60. // Assume square frames.
  61. get { return Texture.Height; }
  62. }
  63. /// <summary>
  64. /// Gets the height of a frame in the animation.
  65. /// </summary>
  66. public int FrameHeight
  67. {
  68. get { return Texture.Height; }
  69. }
  70. /// <summary>
  71. /// Constructors a new animation.
  72. /// </summary>
  73. public Animation(Texture2D texture, float frameTime, bool isLooping)
  74. {
  75. this.texture = texture;
  76. this.frameTime = frameTime;
  77. this.isLooping = isLooping;
  78. }
  79. }
  80. }