IAnimationController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using System;
  5. using Microsoft.Xna.Framework;
  6. namespace MonoGame.Extended.Animations;
  7. /// <summary>
  8. /// Defines the interface for an animation controller with features to play, pause, stop, reset, and set the state of
  9. /// animation playback such as looping, reversing, and ping-pong effects.
  10. /// </summary>
  11. public interface IAnimationController : IDisposable
  12. {
  13. /// <summary>
  14. /// Gets a value indicating whether this animation controller has been disposed of.
  15. /// </summary>
  16. bool IsDisposed { get; }
  17. /// <summary>
  18. /// Gets a value indicating whether the animation is paused.
  19. /// </summary>
  20. bool IsPaused { get; }
  21. /// <summary>
  22. /// Gets a value indicating whether the animation is currently animating.
  23. /// </summary>
  24. bool IsAnimating { get; }
  25. /// <summary>
  26. /// Gets or sets a value indicating whether the animation should loop.
  27. /// </summary>
  28. bool IsLooping { get; set; }
  29. /// <summary>
  30. /// Gets or sets a value indicating whether the animation is reversed.
  31. /// </summary>
  32. bool IsReversed { get; set; }
  33. /// <summary>
  34. /// Gets or sets a value indicating whether the animation should ping-pong (reverse direction at the ends).
  35. /// </summary>
  36. bool IsPingPong { get; set; }
  37. /// <summary>
  38. /// Gets or sets the speed of the animation.
  39. /// </summary>
  40. /// <value>The speed cannot be less than zero.</value>
  41. double Speed { get; set; }
  42. /// <summary>
  43. /// Gets or sets the action to perform when an animation event is triggered.
  44. /// </summary>
  45. event Action<IAnimationController, AnimationEventTrigger> OnAnimationEvent;
  46. /// <summary>
  47. /// Gets the time remaining for the current frame.
  48. /// </summary>
  49. TimeSpan CurrentFrameTimeRemaining { get; }
  50. /// <summary>
  51. /// Gets the index of the current frame of the animation.
  52. /// </summary>
  53. int CurrentFrame { get; }
  54. /// <summary>
  55. /// Gets the total number of frames in the animation.
  56. /// </summary>
  57. int FrameCount { get; }
  58. /// <summary>
  59. /// Sets the animation to a specified frame.
  60. /// </summary>
  61. /// <param name="index">The index of the frame to set.</param>
  62. /// <exception cref="ArgumentOutOfRangeException">
  63. /// Thrown when the <paramref name="index"/> parameter is less than zero or greater than or equal to the total
  64. /// number of frames.
  65. /// </exception>
  66. void SetFrame(int index);
  67. /// <summary>
  68. /// Plays the animation from the beginning.
  69. /// </summary>
  70. /// <returns>
  71. /// <see langword="true"/> if the animation was successfully started; otherwise, <see langword="false"/>.
  72. /// </returns>
  73. bool Play();
  74. /// <summary>
  75. /// Plays the animation from a specified starting frame.
  76. /// </summary>
  77. /// <param name="startingFrame">The frame to start the animation from.</param>
  78. /// <returns>
  79. /// <see langword="true"/> if the animation was successfully started; otherwise, <see langword="false"/>.
  80. /// </returns>
  81. /// <exception cref="ArgumentOutOfRangeException">
  82. /// Thrown when the <paramref name="startingFrame"/> parameter is less than zero or greater than or equal to the
  83. /// total number of frames.
  84. /// </exception>
  85. bool Play(int startingFrame);
  86. /// <summary>
  87. /// Pauses the animation.
  88. /// </summary>
  89. /// <returns>
  90. /// <see langword="true"/> if the animation was successfully paused; otherwise, <see langword="false"/>.
  91. /// </returns>
  92. bool Pause();
  93. /// <summary>
  94. /// Pauses the animation.
  95. /// </summary>
  96. /// <param name="resetFrameDuration">If set to <see langword="true"/>, resets the frame duration.</param>
  97. /// <returns>
  98. /// <see langword="true"/> if the animation was successfully paused; otherwise, <see langword="false"/>.
  99. /// </returns>
  100. bool Pause(bool resetFrameDuration);
  101. /// <summary>
  102. /// Unpauses the animation.
  103. /// </summary>
  104. /// <returns>
  105. /// <see langword="true"/> if the animation was successfully unpaused; otherwise, <see langword="false"/>.
  106. /// </returns>
  107. bool Unpause();
  108. /// <summary>
  109. /// Unpauses the animation.
  110. /// </summary>
  111. /// <param name="advanceToNextFrame">If set to <see langword="true"/>, advances to the next frame.</param>
  112. /// <returns>
  113. /// <see langword="true"/> if the animation was successfully unpaused; otherwise, <see langword="false"/>.
  114. /// </returns>
  115. bool Unpause(bool advanceToNextFrame);
  116. /// <summary>
  117. /// Updates the animation.
  118. /// </summary>
  119. /// <param name="gameTime">A snapshot of the timing values for the current update cycle.</param>
  120. void Update(GameTime gameTime);
  121. /// <summary>
  122. /// Updates the animation.
  123. /// </summary>
  124. /// <param name="elapsedTime">The elapsed time since the last update.</param>
  125. void Update(TimeSpan elapsedTime);
  126. /// <summary>
  127. /// Stops the animation.
  128. /// </summary>
  129. /// <returns>
  130. /// <see langword="true"/> if the animation was successfully stopped; otherwise, <see langword="false"/>.
  131. /// </returns>
  132. bool Stop();
  133. /// <summary>
  134. /// Resets the animation to its initial state.
  135. /// </summary>
  136. void Reset();
  137. }