# ElapsedTime Movement?

This topic is 1929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Many years of programming and I never actually used a proper elapsed time functionality, which promises to run and move game objects in pixels per second rather than pixels per frames.

My question is where do you actually add elapsed time to? Is it every single object that you move? (which sounds like something you will eventually miss) or is it only on the main loop?

My example...?

[Engine] -> Game(delta) -> Player(delta) -> moveRight(delta) - > x += speed*delta;
[Engine] -> Game(delta) -> Enemy(delta) -> jump(delta) - > y -= jumpValue*delta;
[Engine] -> Game(delta) -> BackgroundManager(delta) -> moveBackgrounds(delta) - > for each(bg in bgList) bg.x -= speed*delta;

Am I thinking correctly or..?
Any interesting tutorials someone can link me to?

##### Share on other sites
Working with time instead of frames will give you a more synchronized game. it's also a must when you plan to go online.
Why? Assume you have 50 processes running on your computer and your enemy has 25. Your enemies game-cycle will be called twice as fast. So he will have the advantage.

You add the time to any calculation for movement, shooting, camera, etc.
 m_Velocity = m_Velocity * deltaTime; m_Position = m_Velocity; // you don't need to put a delta time here because it's using the velocity who has a delta time calculated in it. // This is the camera you want to move: m_Camera.moveLeft( int delta ); // Inside the method of the camera: m_CameraPosition.x = m_CameraPosition * deltaTime; // This means you need a method for the camera: void Tick( int deltaTime ) and store the deltaTime !! 

Edit:
If you are not sure to put a delta time with a line of code you need to think on an online game.
Will the code without deltaTime have a possibility to lose synchronization? If yes, add the deltaTime.

~EngineProgrammer Edited by EngineProgrammer

##### Share on other sites
Just do the same thing you normally do, however this time multiply the velocity by the elapsed time.

##### Share on other sites
I just schedule an event to go off every 80 milliseconds, and when it does, update the game logic. Whether or not that event is next in the event queue, I check for input and render the screen. Of course this is not the approach I'd use for an online twitch-based game, but I don't plan on ever writing one.

##### Share on other sites
If you're handling all the entity updates in batch, you only need one delta for all of them. Create your delta and pass it through your updates. Depending on how you go about calculating your delta it can be a subtly costly operation that has little gain. It also mean all objects are synced to the same 'point' in time.

I do all these things in floatational numbers. So time becomes normalized to a second.