I'm looking to change the way in which my game uses
GameTime to run the game so that I can easily pause the game (
elapsedTime = 0) or change how slow/fast the in game elements interact as a scaler of the actual time passed (
elapsedTime *= timeScale).
In my project, I always make the assumption that the game is not running on a fixed time step for a number of reasons. Due to this, any changes of states have the elapsed time factored in from
GameTime. I'm hoping this means I can simply simulate slow-mo, fast-mo, force short freezes (like when you kill an enemy in TLoZ: Windwaker - there's a short pause for emphasis) or pause the game by interfering with the
GameTime.ElapsedGameTime that all of my
Update() code uses.
My first thought is to stop using
GameTime within any update code, and to instead wrap a new class (
MyTime would do the following:
- Seperates real time and game time. Real time is the passage of time outside of the system. Game time is the passage of time within the game's world, i.e if slow motion is in effect, the time passed within the game would be lower for the period of slow motion.
- Time scaling can either be started and ended, or requested to be active for a length of real time or game time.
- Time can be paused or frozen with either manual start and stop calls, or for a length of time, again based on either real or game time.
Based on this discussion, where it's states that
GameTime is recreated every tick within XNA's base
Game class, I'm hestitant to just store a reference to
MyTime as I personally don't know how
GameTime is altered. I also don't know the 'best' way to retrieve the
GameTime reference in the first place, the reference is available within the
Draw() calls, however since
gameTime isn't made available throughout any derived from
Game class, it's implied taking the
gameTime reference out of those update and draw calls isn't intended.
Is my intended implementation of this the right way of achieveing this system? What is a good to expose
MyTime? Should I implement my own way to track time and not rely on
GameTime at all?