Beispiel #1
0
 public Timer StartTimer(float timerLength, int loops, OnTimerComplete onComplete = null)
 {
     TimerLength = timerLength;
     Loops       = loops;
     OnComplete  = onComplete;
     Active      = true;
     CurrentLoop = 0;
     ElapsedTime = 0f;
     return(this);
 }
Beispiel #2
0
        protected override void Update()
        {
            if (IsRunning)
            {
                RemainingTime = System.Math.Max(0, RemainingTime - Application.Time.DeltaTime);

                OnTimerTick?.Invoke(this);

                if (RemainingTime == 0)
                {
                    IsRunning = false;
                    OnTimerComplete?.Invoke(this);
                }
            }
        }
Beispiel #3
0
        public override void Update(float deltaTime)
        {
            if (IsRunning)
            {
                RemainingTime = Math.Max(0, RemainingTime - deltaTime);

                OnTimerTick?.Invoke(this);

                if (RemainingTime == 0)
                {
                    IsRunning = false;
                    OnTimerComplete?.Invoke(this);
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Updates the timer
 /// </summary>
 /// <param name="gameTime">The <see cref="GameTime"/> of the game</param>
 public void Update(GameTime gameTime)
 {
     if (ElapsedTime < Time)
     {
         ElapsedTime += gameTime.ElapsedGameTime.TotalSeconds;
     }
     else
     {
         OnTimerComplete?.Invoke(this, new EventArgs());
         if (IsLooping)
         {
             ElapsedTime -= Time;
         }
     }
 }
Beispiel #5
0
 public void SetOnCompleteCallback(OnTimerComplete callback)
 {
     onTimerComplete = callback;
 }
Beispiel #6
0
 /// <summary>
 /// Runs the timer.
 /// </summary>
 /// <param name="_callback">Callback.</param>
 /// <param name="_sec">Sec.</param>
 /// <param name="_isLoop">If set to <c>true</c> is loop.</param>
 public void RunTimer(OnTimerComplete _callback, float _sec, bool _isLoop = false)
 {
     SetOnCompleteCallback(_callback);
     RunTimer(_sec, _isLoop);
 }