TimerNum toggle; //flips between the 2 timers #endregion Fields #region Constructors public Timer2(int timeSpan1, int timeSpan2) { span1 = timeSpan1; span2 = timeSpan2; counter = 0; toggle = TimerNum.First; }
public TimerNum Update(GameTime gameTime) { //accumulate elapsed time counter += gameTime.ElapsedGameTime.Milliseconds; switch (toggle) { case TimerNum.First: if (counter >= span1) //span1 finished { counter %= span1; //remove accumulated span1 time toggle = TimerNum.Second; //flip toggle } break; case TimerNum.Second: if (counter >= span2) //span2 finished { counter %= span2; //remove accumulated span2 time toggle = TimerNum.First; //flip toggle } break; } return(toggle); }
int counter; //the time accumulator public Timer2(int timeSpan1, int timeSpan2) { span1 = timeSpan1; span2 = timeSpan2; counter = 0; toggle = TimerNum.First; }
private void StartCountDown() { InCountdownState = true; CountDownNum = 3; TimerNum.Elapsed += CountdownEvent; TimerNum.Interval = 1000; TimerNum.Start(); String s = TimerNum.ToString(); }
public void CountdownEvent(Object Sender, ElapsedEventArgs args) { CountDownNum -= 1; if (CountDownNum == 0) { TimerNum.Stop(); InCountdownState = false; this._status = GameStatus.InProgress; game.Update(game); CountDownNum = 3; TimerNum.Elapsed -= CountdownEvent; } }
public TimerNum Update(GameTime gameTime) { //accumulate elapsed time counter += gameTime.ElapsedGameTime.Milliseconds; switch (toggle) { case TimerNum.First: if (counter >= span1) //span1 finished { counter %= span1; //remove accumulated span1 time toggle = TimerNum.Second; //flip toggle } break; case TimerNum.Second: if (counter >= span2) //span2 finished { counter %= span2; //remove accumulated span2 time toggle = TimerNum.First; //flip toggle } break; } return toggle; }
//Reset the timer back to beginning public void Reset() { toggle = TimerNum.First; counter = 0; }
//Reset the timer back to beginning public void Reset() { toggle = TimerNum.First; counter = 0; }