Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

ElapsedTime Movement?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 IggyZuk   Members   


Posted 07 October 2012 - 10:01 AM

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?

Start by doing what is necessary; then do what is possible; and suddenly you are doing the impossible.

#2 EngineProgrammer   Members   


Posted 07 October 2012 - 03:16 PM

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 !!

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.

I hope this was helpful.


Edited by EngineProgrammer, 07 October 2012 - 03:19 PM.

#3 superman3275   Members   


Posted 07 October 2012 - 03:32 PM

Just do the same thing you normally do, however this time multiply the velocity by the elapsed time.

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!


Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:


or Personal-Message me on here smile.png!

#4 Heath   Members   


Posted 07 October 2012 - 06:13 PM

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.

#5 RevenantBob   Members   


Posted 10 October 2012 - 02:21 PM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.