Bleh.

3 min read

Deviation Actions

Terrance8d's avatar
By
Published:
1K Views
So after about a day of messing around with my new favorite subject, "timesteps", I don't even know if I care about trying to build games from scratch in C++ anymore. I mean, this was REALLY confusing, so much that it singlehandedly, was enough to make say that. I was feeling pretty good about learning about SFML, and then that showed up.

For those of you who haven't tried to make games without an existing before, a timestep is actually a simple topic. In a game, what's being displayed on the screen is happening many, many times per second. Usually around 60 times in the course of second. Now, usually the speed of those updates will be as fast as your computer can manage. If you have a slow computer, it could be less that 60 times per second and you could see some lag. That's generally not a good idea.
So, you try to manage how often this happens. First, you get the current system time in seconds, let's call that current_time. Then, inside of your infinite update loop, you get the time again, which we'll call new_time. After that, you get the frame time, which is the difference between new_time and current_time, so frame_time = new_time - current_time. Then you usually sleep the loop for the frame time. In other words, you delay the loop by that time. All is well and good, until you run that on a really fast or a really slow computer, in which case the game will actually speed up or slow down depending on the framerate. Not good.
So, you have to do something a lot more advanced. What you do is you make sure that everything is running independently from the framerate. As an example, instead of moving an object at a rate of 1 ft/frame, you would move it 60 ft/second. Sounds simple enough, but it's so complicated to implement for your specific project that it drove me nuts.

If you read all that, congrats. So, I think I'm done trying to create games from scratch with C++/SFML for awhile at least. I don't want to just stop making games, I'll probably find a 2D game engine. For now, I'm finished with that nonsense though.

Edit:
I decided to suck it up and try to learn about timesteps some more, and after a day or so, I actually got the hang of it. I've been developing a basic game as practice, here's what I have so far.  Success by Terrance8d Totally amazing :P This is the result of about a day's work, so it's not exactly what you'd call "playable", in fact, the tile displayed on the screen is a bit of a hack. I have to implement a better way to draw tiles because this way requires creating a Tile object for each texture you want to display. Both inconvenient and horribly inefficient.
© 2016 - 2024 Terrance8d
Comments18
Join the community to add your comment. Already a deviant? Log In
AbdouBouam's avatar
You know what? Screw JS, C++ FTW!
Also, nice tile :eyes: