Animation.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework.Content;
  12. using System.Diagnostics;
  13. #endregion
  14. namespace RolePlayingGameData
  15. {
  16. /// <summary>
  17. /// An animation description for an AnimatingSprite object.
  18. /// </summary>
  19. #if !XBOX
  20. [DebuggerDisplay("Name = {Name}")]
  21. #endif
  22. public class Animation : ContentObject
  23. {
  24. /// <summary>
  25. /// The name of the animation.
  26. /// </summary>
  27. private string name;
  28. /// <summary>
  29. /// The name of the animation.
  30. /// </summary>
  31. [ContentSerializer(Optional = true)]
  32. public string Name
  33. {
  34. get { return name; }
  35. set { name = value; }
  36. }
  37. /// <summary>
  38. /// The first frame of the animation.
  39. /// </summary>
  40. private int startingFrame;
  41. /// <summary>
  42. /// The first frame of the animation.
  43. /// </summary>
  44. public int StartingFrame
  45. {
  46. get { return startingFrame; }
  47. set { startingFrame = value; }
  48. }
  49. /// <summary>
  50. /// The last frame of the animation.
  51. /// </summary>
  52. private int endingFrame;
  53. /// <summary>
  54. /// The last frame of the animation.
  55. /// </summary>
  56. public int EndingFrame
  57. {
  58. get { return endingFrame; }
  59. set { endingFrame = value; }
  60. }
  61. /// <summary>
  62. /// The interval between frames of the animation.
  63. /// </summary>
  64. private int interval;
  65. /// <summary>
  66. /// The interval between frames of the animation.
  67. /// </summary>
  68. public int Interval
  69. {
  70. get { return interval; }
  71. set { interval = value; }
  72. }
  73. /// <summary>
  74. /// If true, the animation loops.
  75. /// </summary>
  76. private bool isLoop;
  77. /// <summary>
  78. /// If true, the animation loops.
  79. /// </summary>
  80. public bool IsLoop
  81. {
  82. get { return isLoop; }
  83. set { isLoop = value; }
  84. }
  85. #region Constructors
  86. /// <summary>
  87. /// Creates a new Animation object.
  88. /// </summary>
  89. public Animation() { }
  90. /// <summary>
  91. /// Creates a new Animation object by full specification.
  92. /// </summary>
  93. public Animation(string name, int startingFrame, int endingFrame, int interval,
  94. bool isLoop)
  95. {
  96. this.Name = name;
  97. this.StartingFrame = startingFrame;
  98. this.EndingFrame = endingFrame;
  99. this.Interval = interval;
  100. this.IsLoop = isLoop;
  101. }
  102. #endregion
  103. #region Content Type Reader
  104. /// <summary>
  105. /// Read an Animation object from the content pipeline.
  106. /// </summary>
  107. public class AnimationReader : ContentTypeReader<Animation>
  108. {
  109. /// <summary>
  110. /// Read an Animation object from the content pipeline.
  111. /// </summary>
  112. protected override Animation Read(ContentReader input,
  113. Animation existingInstance)
  114. {
  115. Animation animation = existingInstance;
  116. if (animation == null)
  117. {
  118. animation = new Animation();
  119. }
  120. animation.AssetName = input.AssetName;
  121. animation.Name = input.ReadString();
  122. animation.StartingFrame = input.ReadInt32();
  123. animation.EndingFrame = input.ReadInt32();
  124. animation.Interval = input.ReadInt32();
  125. animation.IsLoop = input.ReadBoolean();
  126. return animation;
  127. }
  128. }
  129. #endregion
  130. }
  131. }