1using System.Runtime.Serialization;
13[JsonObject(IsReference =
true)]
14public class Cycle : ICloneable, IDisposable
16 [Newtonsoft.Json.JsonIgnore]
internal DefinitionProvenance? DefinitionProvenance {
get;
set; }
28 [JsonProperty]
public readonly
string CycleKey;
35 internal long _throttle = 0;
39 #region constructors / destructor
52 bool hideTileOnCycleEnd =
false)
60 if (
Cycle._cycles.ContainsKey(cycleKey))
61 Cycle._cycles[cycleKey] =
this;
63 Cycle._cycles.Add(cycleKey,
this);
69 _throttle = fromCycle._throttle;
70 _throttleTime = fromCycle._throttleTime;
77 private void OnDeserialized(StreamingContext context)
85 #endregion constructors / destructor
87 #region public properties
89 private double _throttleTime;
96 internal long CurrentFrameThrottle
101 return !
double.IsFinite(ticks) || ticks < 1 || ticks >= long.MaxValue ? 0 : (long)ticks;
111 get {
return _throttleTime; }
114 _throttle = (long)(value * (
double)HighResTimer.TicksPerSecond);
115 _throttleTime = value;
127 if (Enumerable.Range(0,
Sequence.FrameCount).Any(i =>
Sequence.GetDurationSeconds(i).HasValue))
131 for (
int i = 0; i <
Sequence.FrameCount; i++)
170 #endregion public properties
172 #region ICloneable Members
180 return new Cycle(
this);
183 #endregion ICloneable Members
185 #region IDisposable Members
192 GC.SuppressFinalize(
this);
197 sprite.TileAnimator.CurrentCycle =
null;
203 #endregion IDisposable Members
205 #region static members
207 internal static readonly Dictionary<string, Cycle> _cycles =
new(StringComparer.OrdinalIgnoreCase);
212 public static int Count => _cycles.Count;
233 if (_cycles.ContainsKey(cycleKey))
245 if (_cycles.ContainsKey(cycleKey))
246 _cycles[cycleKey].Dispose();
254 var tempCycles =
new List<Cycle>(_cycles.Values);
256 foreach (
Cycle cyc
in tempCycles)
260 #endregion static members
References a FrameSequence object, along with a particular Throttle value for animating through Frame...
static void ClearAllAnimationCycles()
Removes and disposes all registered animation cycles.
double TotalCycleTime
Returns the total time in seconds for the Cycle.
static int Count
Gets the total number of animation cycles currently registered.
double ThrottleTime
Gets or sets the time in seconds between frame transitions in the animation cycle.
object Clone()
Creates a shallow copy of the current Cycle instance.
double CurrentFrameDurationSeconds
Effective duration of the currently displayed frame.
Cycle NextCycle
Gets or sets the next cycle to transition to when this cycle completes.
static void ClearAnimationCycle(string cycleKey)
Removes and disposes the animation cycle with the specified key.
Cycle(FrameSequence sequence, double throttleTime, string cycleKey, bool hideTileOnCycleEnd=false)
Initializes a new instance of the Cycle class.
static Cycle GetAnimationCycle(string cycleKey)
Retrieves a clone of the animation cycle with the specified key.
void Dispose()
Releases all resources used by the Cycle and removes it from the static cycle collection.
readonly bool HideTileOnCycleEnd
Indicates whether the tile should be hidden when the cycle completes.
FrameSequence Sequence
The frame sequence used by this animation cycle.
static List< string > GetAnimationCycleKeys()
Retrieves a list of all registered animation cycle keys.
static List< Cycle > GetAnimationCycles()
Retrieves a list of all registered animation cycles.
readonly string CycleKey
The unique identifier key for this cycle.
Manages the lifecycle, lookup, and per-frame updates of all active Sprite instances.
static SpriteManager Instance
Gets the singleton instance of the sprite manager.
Represents a movable visual element on a scene layer.
virtual Animator TileAnimator
Gets the animator associated with this tile.
CycleType
Simple is self-terminating; the other two are repeating.
Represents a sequence of animation frames that can be cycled through using different animation patter...