I have recently finished a level editor that I plan to use to create levels for a 2D platformer that I am working on. Now, I am working on a program that will actually play the levels and let the user play them. However, I intend to sell this game, so it will need to be fast, and run the same speed on all computers. For it to do this, the main game loop will need to be structured well. I understand I will need to use timers, especially for rendering the game, but what would be the best way to go about this? Also, does it matter what order I do the tasks in? For example, should I take their input before I draw them? When should I test if they are on solid ground? Also, I am programming in Blitz Plus, so pseudocode would be appreciated if possible. Thanks.
Making a fast, efficient main game loop for a 2D platformer?
Started by nicksaiz65, Nov 04 2012 08:29 PM
5 replies to this topic
Sponsor:
#2 Members - Reputation: 625
Posted 04 November 2012 - 09:44 PM
You should calculate how much time has passed between each frame and use that time to update your game
And if you are running some physics, it is good idea to use fixed fps. To do this you can create some delay between each frame if a frame is finished early.
Every game loop will look similar to this
[source lang="cpp"]while(GameIsOn){ handleEvent(); update(delta_time); draw();}[/source]
And if you are running some physics, it is good idea to use fixed fps. To do this you can create some delay between each frame if a frame is finished early.
Every game loop will look similar to this
[source lang="cpp"]while(GameIsOn){ handleEvent(); update(delta_time); draw();}[/source]
An invisible text.
#3 Staff - Reputation: 8994
Posted 04 November 2012 - 09:55 PM
- Jason Astle-Adams.
From my blog: 20 ways to advertise your game | What next? Intermediate to advanced C++
How to make games WITHOUT programming | 4 reasons you aren't a successful indie developer
#4 Members - Reputation: 650
Posted 05 November 2012 - 09:19 PM
Try reading through "fix your timestep" and "deWiTTERS game loop".
Classic articles, especially the Gaffer one.
After reading deWitter, I am wondering: Is it really fair to say that the "constant game speed" solutions help with input response time on slower machines? The article certainly seems to suggest that, stating it as a flaw of the other approaches. Furthermore, this idea is reinforced by the notion that your game logic will be independent from your rendering. However, what you are really doing is giving your physics simulation time to catch up if the rendering is running slow. The catching up is done in a rapid sequence of fixed-length incremental steps. If I am not mistaken, the main purpose of this is to make sure that your simulation is well behaved. However, this should not really affect input response time, right? In a sense, the simulation is running in virtual time, whereas user input happens in real time.
Either way, it is a good article on an interesting topic. The intent of my post is to verify that my understanding is correct and to help others that may be confused.
Edited by kloffy, 05 November 2012 - 09:26 PM.
#6 Crossbones+ - Reputation: 5340
Posted 07 November 2012 - 09:26 PM
Fixed frame rate or fixed logical-update rate?
They are not the same thing. The frame rate should be whatever it can be. Logical updates should be fixed (usually to around 30 times per second).
L. Spiro
They are not the same thing. The frame rate should be whatever it can be. Logical updates should be fixed (usually to around 30 times per second).
L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums






