Browse Source

Add Pause at end of animation in auto-mode.

Dominique Louis 1 tháng trước cách đây
mục cha
commit
26717069e2
1 tập tin đã thay đổi với 9 bổ sung1 xóa
  1. 9 1
      ShatterEffectSample/Core/ShatterEffectGame.cs

+ 9 - 1
ShatterEffectSample/Core/ShatterEffectGame.cs

@@ -45,6 +45,8 @@ namespace ShatterEffect
         bool autoShatter = false;
         bool autoShatterReversing = false;
         float autoShatterSpeed = 0.5f; // Slow-motion multiplier for auto-shatter
+        float autoShatterPauseDuration = 1.0f; // Pause duration in seconds before changing direction
+        float autoShatterPauseTimer = 0.0f; // Timer to track pause duration
         KeyboardState previousKeyboardState;
 
         public ShatterEffectGame()
@@ -99,13 +101,18 @@ namespace ShatterEffect
             {
                 float adjustedElapsedTime = elapsedTime * autoShatterSpeed; // Apply slow-motion multiplier
 
-                if (!autoShatterReversing)
+                if (autoShatterPauseTimer > 0.0f)
+                {
+                    autoShatterPauseTimer -= elapsedTime; // Decrease pause timer
+                }
+                else if (!autoShatterReversing)
                 {
                     time += adjustedElapsedTime;
                     if (time >= duration)
                     {
                         time = duration;
                         autoShatterReversing = true;
+                        autoShatterPauseTimer = autoShatterPauseDuration; // Start pause timer
                     }
                 }
                 else
@@ -115,6 +122,7 @@ namespace ShatterEffect
                     {
                         time = 0.0f;
                         autoShatterReversing = false;
+                        autoShatterPauseTimer = autoShatterPauseDuration; // Start pause timer
                     }
                 }
             }