Animation.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 Platformer2D
  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. // Assume square frames.
  54. get { return Texture.Width / FrameHeight; }
  55. }
  56. /// <summary>
  57. /// Gets the width of a frame in the animation.
  58. /// </summary>
  59. public int FrameWidth
  60. {
  61. // Assume square frames.
  62. get { return Texture.Height; }
  63. }
  64. /// <summary>
  65. /// Gets the height of a frame in the animation.
  66. /// </summary>
  67. public int FrameHeight
  68. {
  69. get { return Texture.Height; }
  70. }
  71. /// <summary>
  72. /// Constructors a new animation.
  73. /// </summary>
  74. public Animation(Texture2D texture, float frameTime, bool isLooping)
  75. {
  76. this.texture = texture;
  77. this.frameTime = frameTime;
  78. this.isLooping = isLooping;
  79. }
  80. }
  81. }