From e8698d7c6ec6c1a7c699efd7f80f21383c62ec65 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 28 Dec 2012 16:57:08 -0600 Subject: [PATCH] Fixing bug with Axios Timer --- axios/Engine/AxiosTimer.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/axios/Engine/AxiosTimer.cs b/axios/Engine/AxiosTimer.cs index a49c134..a9d2708 100644 --- a/axios/Engine/AxiosTimer.cs +++ b/axios/Engine/AxiosTimer.cs @@ -16,6 +16,7 @@ namespace Axios.Engine TimeSpan interval = new TimeSpan(0, 0, 1); TimeSpan lastTick = new TimeSpan(); private bool _enabled = false; + public TimeSpan? offset = null; public event EventHandler Tick; @@ -38,12 +39,21 @@ namespace Axios.Engine public override void Update(AxiosGameScreen gameScreen, GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { - + // Issue here: if you add a timer later on and use the algorithm of + // gameTime.TotalGameTime - lastTick >= interval + // The timer will always run + // What we should do is have an offset of the time it was added like this: + // ((gameTime.TotalGameTime - offset) - lastTick) >= interval if (gameScreen.ScreenManager.Game.IsActive) //only "tick" if the window has focus - otherwise the Timer will play catchup { + if (offset == null) + { + offset = gameTime.TotalGameTime; + return; + } if (_enabled) { - if (gameTime.TotalGameTime - lastTick >= interval) + if (((gameTime.TotalGameTime - offset) - lastTick) >= interval) { if (Tick != null) {