# How to change speed of passage of time?

I have begun creating a very simple game engine and I am trying to work out how to create a time scale for the game. By time scale I mean some way of increasing and decreasing the speed of the game (not the fps) like creating a slow motion effect.

I have no idea how this could be accomplished so any help would be appreciated.

If this helps I'm using windows, OpenGL, and C++ to make my game engine.

How my engine is setup:

I have an update and draw function. The update function is called 25 times per second while display is called as much as possible.

I'm not sure about the architecture of your game, so what's follow is a rather generic answer. Usually there are two different 'rates' in the game - the screen refresh or draw rate, and the logic update rate.

The draw rate is the FPS - some game engines will try to draw as often as possible, while others will try to draw at a fixed rate. Regardless, it is not a good idea to tie logic updating to the draw rate of your game.

Most game engines instead will have a update loop, which is governed by the logic update rate. This is the rate you you to speed up, slow down, or pause the game. To pause, you simple stop updating. To slow down, you increase the time between each update, and so on.

As an example, Unity3D has a variable called Time.timeScale, which affects the Time.deltaTime variable used by all most logic functions to determine the elapsed time each frame. By setting the time scale to 1.0f, the game runs at normal speed. Setting it at 0.5f will run it half the speed.

• yeah i got the idea from unity and was hoping to be able to make something similar in my engine ill update my question and add a little more detail as to how my engine is setup.. And thanks for the help...i will attempt to implement it now :D Commented May 22, 2011 at 9:44
• thanks for your help...i managed to implement time scale into my game :D. Commented May 24, 2011 at 10:13

I guess the easiest way is to change delta_time value you pass to your update functions, for example if you tell your update function that the last frame took 1/120s but having 1/60s for a real frame, it makes your game to update half normal speed (it doesn't affect controls but may cause some side effects like delaying buttons and etc.)

In Ogre3D, and I suspect many other engines, you'll get a callback when the latest frame has been queued to render. This can be (and often is) your source for relaying "time" to the rest of your application.

void frameRenderQueued(FrameEvent ev)
{
double scaledTime = ev.timeSinceLastFrame * MY_TIME_SCALE;

// Stuff that needs scaled time

modifiedDeltaTime = deltaTime * scale;