Jump to content

  • Log In with Google      Sign In   
  • Create Account


ElapsedTime Movement?


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   -  Reputation: 926

Like
1Likes
Like

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.


Sponsor:

#2 EngineProgrammer   Members   -  Reputation: 295

Like
0Likes
Like

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

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.

I hope this was helpful.


~EngineProgrammer

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


#3 superman3275   Crossbones+   -  Reputation: 2011

Like
0Likes
Like

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:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#4 Heath   Members   -  Reputation: 344

Like
0Likes
Like

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   -  Reputation: 114

Like
1Likes
Like

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.



PARTNERS