Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 help im using windows, Opengl and C++ in the game engine...

How my engine is setup i have an update and draw function...update is called 25 times per second while display is called as much as possible.

share|improve this question

4 Answers 4

up vote 6 down vote accepted

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.

share|improve this answer
    
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 –  I Phantasm I May 22 '11 at 9:44
    
thanks for your help...i managed to implement time scale into my game :D. –  I Phantasm I May 24 '11 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 functions that the last fram 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 couse some side effect like delaying buttons and etc.)

share|improve this answer

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
   myAnimationManager->addTimeToAllAnimations(scaledTime);
   myParticleEffectsManager->addTimeToAllParticleEffects(scaledTime);
   myBuffManager->addTimeToAllBuffs(scaledTime);

   // Stuff that doesn't need scaled time
   myPopupManager->addTimeToPopups(ev.timeSinceLastFrame);
}

In the above code, you can see that you can pass scaled time along to the things you want to slow down (animations and such, and if your game operates in "real time", any effects like buffs that are designed to last a certain amount of time in-game), but use the unscaled time for things that you wouldn't expect to be affected, like a pop-up in your UI and such.

share|improve this answer

Assuming you use a delta time for updating. Just multiply it by a scalar modifier that reflects how fast or slow you want time to progress. For example, 1.0 for standard speed or 0.5 for half.

modifiedDeltaTime = deltaTime * scale; 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.