/// <summary> /// Updates this instance. /// </summary> /// <param name="deltaTime"> /// The amount of time, in seconds, that have passed since /// the last update. Usually gathered from GameTime.ElapsedTime.TotalSeconds /// </param> public override void Update(float deltaTime) { if (Animating && !Paused) { // Using an epsilon of 0.0001 to check for equality between // the FrameTimer (double) and duration (float). This is to handle // edge cases where precision loss in the float may cause this to // skip. if (Math.Abs(FrameTimer - CurrentFrame.Duration) < 0.0001) { // We're at the beginning of the frame so invoke the // Action OnFrameBegin?.Invoke(); } // Decrement the frame timer FrameTimer -= deltaTime; // Check if we need to move on to the next frame if (FrameTimer <= 0) { AdvanceFrame(); } } }
/// <summary> /// Updates this /// </summary> /// <param name="deltaTime"> /// The amount of time, in seconds, that have passed since /// the last update. Usually gathered from GameTime.ElapsedTime.TotalSeconds /// </param> public override void Update(float deltaTime) { if (Animating) { // Using an epsilon of 0.0001 to check for equality between // the Framtimer (double) and duration (float). This is to handle // edge cases where precision loss in the float may cause this to // skip. if (Math.Abs(FrameTimer - CurrentFrame.duration) < 0.0001) { // We're at the beginning of the frame so invoke the // Action OnFrameBegin?.Invoke(); } // Decrement the frame timer FrameTimer -= deltaTime; // Check if we need to move on to the next frame if (FrameTimer <= 0) { // We're now at the end of a frame, so invoke the action OnFrameEnd?.Invoke(); // Increment the frame index CurrentFrameIndex += 1; // Check that we are still within the bounds of the animations frames if (CurrentFrameIndex > CurrentAnimation.to) { // Loop back to the beginning of the animations frame CurrentFrameIndex = CurrentAnimation.from; // Since we looped, invoke the loop aciton OnAnimationLoop?.Invoke(); } // Set the CurrentFrame CurrentFrame = _animationDefinition.Frames[CurrentFrameIndex]; // Set the Duration FrameTimer = (double)CurrentFrame.duration; } } }