Animation.cs 3.9 KB

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