Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
Animator.cs
2
4
8public class Animator : IDisposable
9{
10 #region events
11
15 public event Action<AnimatorEventArgs> Started;
16
20 public event Action<AnimatorEventArgs> Stopped;
21
25 public event Action<AnimatorEventArgs> Cycled;
26
27 #endregion events
28
29 #region private/internal fields
30
31 private readonly Tile parent;
32 private bool cycling = false;
33 private long LastTick = EngineSimulationClock.GetCurrentTick();
34
35 #endregion private/internal fields
36
37 #region constructors / finalizer
38
43 protected internal Animator(Tile tile)
44 {
45 parent = tile;
46 }
47
51 ~Animator()
52 {
53 Dispose();
54 }
55
56 #endregion constructors / finalizer
57
58 #region properties
59
63 public Tile Parent
64 {
65 get { return parent; }
66 }
67
71 public Cycle CurrentCycle { get; set; }
72
77 public bool IsCycling
78 {
79 get { return cycling; }
80 set
81 {
82 if (cycling != value)
83 {
84 if (value == true)
86 else
88 }
89 }
90 }
91
92 #endregion properties
93
94 #region public methods
95
101 public Cycle SetCurrentCycle(string cycleKey)
102 {
104 return CurrentCycle;
105 }
106
112 public void StartAnimation()
113 {
114 if (CurrentCycle != null)
115 {
116 cycling = true;
117
118 if (Tile.TilesAnimating.IndexOf(parent) == -1)
119 Tile.TilesAnimating.Add(parent);
120
121 if (Started != null)
122 Started(new AnimatorEventArgs(parent, this));
123 }
124 }
125
130 public void StartAnimation(string cycleKey)
131 {
134 }
135
141 public void StopAnimation()
142 {
143 // only perform action if actually cycling
144 if (cycling)
145 {
146 cycling = false;
147 CurrentCycle.Sequence.StopCycle();
148
149 Tile.TilesAnimating.Remove(parent);
150
151 if (Stopped != null)
152 Stopped(new AnimatorEventArgs(parent, this));
153
154 if (CurrentCycle?.NextCycle != null)
155 CurrentCycle = CurrentCycle.NextCycle;
156 else if (CurrentCycle?.NextCycle.HideTileOnCycleEnd == true)
157 parent.Visible = false;
158 }
159 }
160
161 internal void CycleAnimation(long currentTick)
162 {
163 if (CurrentCycle is null)
164 return;
165
166 var throttle = CurrentCycle.CurrentFrameThrottle;
167
168 // if throttle is 0, stop the animation so loop doesn't hang
169 if (throttle <= 0)
170 {
172 return;
173 }
174
175 //if "throttle" time has passed
176 while (currentTick >= LastTick + throttle)
177 {
178 // capture the LastTick value
179 LastTick += throttle;
180
181 // do not change image if animation is paused
182 if (parent.PauseAnimation)
183 return;
184
185 // cycle the frame and set the sprite image; this will add it to RefreshQueue
186 parent.CurrentFrame = CurrentCycle.Sequence.AdvanceFrame();
187
188 // raise the event
189 Cycled?.Invoke(new AnimatorEventArgs(parent, this));
190
191 // if terminating cycle is done, stop the animation
193 {
195 return;
196 }
197
198 // recalculate throttle for the new current frame
199 throttle = CurrentCycle.CurrentFrameThrottle;
200 if (throttle <= 0)
201 {
203 return;
204 }
205 }
206 }
207
208 #endregion public methods
209
210 #region IDisposable Members
211
216 public void Dispose()
217 {
218 Started = null;
219 Stopped = null;
220 Cycled = null;
221 GC.SuppressFinalize(this);
222 }
223
224 #endregion IDisposable Members
225}
Provides data for animator-related events, containing references to the tile and animator involved in...
Manages animation playback for a Tile, controlling animation cycles, frame timing,...
Definition Animator.cs:9
Action< AnimatorEventArgs > Started
Occurs when an animation starts playing.
Definition Animator.cs:15
Cycle SetCurrentCycle(string cycleKey)
Sets the current animation cycle using the specified cycle key.
Definition Animator.cs:101
Cycle CurrentCycle
Gets or sets the current animation cycle being played.
Definition Animator.cs:71
Action< AnimatorEventArgs > Stopped
Occurs when an animation stops playing.
Definition Animator.cs:20
bool IsCycling
Gets or sets a value indicating whether the animation is currently cycling. Setting this property to ...
Definition Animator.cs:78
void StartAnimation()
Starts playing the current animation cycle. If no cycle is set, this method has no effect....
Definition Animator.cs:112
Tile Parent
Gets the tile that owns this animator.
Definition Animator.cs:64
void StopAnimation()
Stops the current animation cycle. Raises the Stopped event and advances to the next cycle if one is ...
Definition Animator.cs:141
void Dispose()
Releases all event handlers and suppresses finalization. *** DO NOT CALL DIRECTLY!...
Definition Animator.cs:216
Action< AnimatorEventArgs > Cycled
Occurs each time the animation advances to the next frame in the cycle.
Definition Animator.cs:25
void StartAnimation(string cycleKey)
Sets the current animation cycle and starts playing it.
Definition Animator.cs:130
References a FrameSequence object, along with a particular Throttle value for animating through Frame...
Definition Cycle.cs:14
static Cycle GetAnimationCycle(string cycleKey)
Retrieves a clone of the animation cycle with the specified key.
Definition Cycle.cs:225
FrameSequence Sequence
The frame sequence used by this animation cycle.
Definition Cycle.cs:24
Represents an abstract base class for drawable tiles in the Gondwana engine. Provides core functional...
Definition Tile.cs:19
static List< Tile > TilesAnimating
Gets the collection of all tiles that are currently animating in the scene.
Definition Tile.cs:25
bool CycleFinished
Gets a value indicating whether the animation cycle has finished playing through the sequence.