How to change speed of passage of time?

I Phantasm I
  • How to change speed of passage of time? I Phantasm I

    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.

  • 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.)

c++ game-mechanics game-loop
Related questions and answers
  • Hey so I'm making a pong game with SFML and in the process made a function that takes a Time, Speed, Angle of movement, buffer for the movement on the X axis, and buffer for the movement on the Y axis. I then implemented this function into my custom mySprite class, more specifically into it's update() function which updates its Position using the above function to calculate its new position... between frame updates or other problems..... Finally I would like to know how my organization, planning, etc is.. Thanks! my UPDATED, WORKING Code: #include<SFML/Graphics.hpp> #include<

  • ? Something unnecessary that maybe you guys could spot? Both MD2 and 3DS loader have an InitToon() function called upon creation to load the shader initToon(){ int i...I am quite new to OpenGL, I have managed after long trial and error to integrate Nehe's Cel-Shading rendering with my Model loaders, and have them drawn using the Toon shade and outline AND their original texture at the same time. The result is actually a very nice Cel Shading effect of the model texture, but it is havling the speed of the program, it's quite very slow even with just 3 models

  • I want to be able to (only) define game states using Lua script, but I'm not sure how I should do it. Here's what I have in mind currently: For each state, I will create a .lua file that contains... exiting the state). So if I want to have a MainMenuState, I will have a file called "MainMenuState.lua" which will contain something like this: MainMenuState = {} MainMenuState["onEnter"] = function() end MainMenuState["onUpdate"] = function(elapsedTime) end MainMenuState["onExit"] = function() end Defined states will be exposed to the game engine via a singleton StateManager class

  • I've decided I want to write a central ResourceManager/ResourceCache class for my hobby game engine, but am having trouble designing a caching scheme. The idea is that the ResourceManager has...)); } // Generally, this will automatically load/unload data, and is called // once per frame. It's also where the caching scheme comes into play. void update(); }; The trouble... of priority system, (eg. Temporary Priority, Frequently Used Priority, Permanent Priority), combined with the time of the last dereference, and the size of the resource, to determine when to remove it. But I

  • in the main function * not Finally.. but i believe that te numb_coll problem has something to do with the time and framrate. When running full speed i quickly die upon entering a wall as numb_coll... #include <sstream> // gives access to rand function #include <cstdlib> //gives access to time functions #include <ctime> // mySTOPWATCH i think i'm gonna cry.... =') #include <... }; mvaddstr(time_loc_y, time_loc_x, myStopwatch.ClockTime().c_str());} refresh();}; // end of function /////////////////////////////////////////// Insert

  • Suppose I have a Spacecraft object in 3D space, controllable by the player. I want it to update its own trajectory, so I give it a function for that (actually it might be inside a controller component associated with it). No problem until this point. For this function I want to use a scientifically tested, accurate N-body simulation algorithm (like this). It's my field so I already know how to do that. The challenge is how to make the game activate the function efficiently. This is what I've thought of so far: The algorithm can calculate a lot of time steps in a short time, so I could

  • *) (node)); // Add it to the physics world World->addRigidBody(RigidBody); Objects.push_back(RigidBody); m_pNumEntities++; // End Physics } I then have a method to create a cube and give it rigid body...I have been playing around with Ogre3d and trying to integrate bullet physics. I have previously somewhat successfully got this functionality working with irrlicht and bullet and I am trying to base this on what I had done there, but modifying it to fit with Ogre. It is working but not correctly and I would like some help to understand what it is I am doing wrong. I have a state system and when

  • : should I be considering creating my own little "game engine", learning through it, adding features as I need them ? I think it could be a really good experience, but it would certainly take time as I'm no professional, and I don't have a clear view of "how-to" yet. I am using SFML with C++. ... Possible Duplicate: When to roll your own game engine? I've been interested in writting games for a while, and now that I have acquired a bit of experience in programming, I feel like I

  • Like many beginner graphics programmers I followed a tutorial which showed me how to set up buffer descriptions and fill out the vertex buffer etc... - the steps involved in drawing a simple indexed cube on the screen. There is a leap however when it comes to drawing more than one of these cubes. My code below is the original cube drawing code, if called more than once, each call overwrites...(pVoid, OurIndices, sizeof(OurIndices)); // copy the indices to the buffer iBuffer->Unmap(); //this is simply a single call to the update method that sets up the scale, rotation //and translation

Data information