C / C++ - How to manage the cycles in a video game? -
i have made video games in c (small personal project). , problem encountered every time same, how manage cycles in game.
for example, coded snake in sfml. handled cycles frame rates: 5 frame rates while normal, , power up, changed 10. works. it's hideous. , won't work correctly bad computer. in same idea, made game decided cycle equal turn of loop (with infinite loop). same problem, high performance computer go faster low one.
so, can advice me on how manage correctly , cycles in video game.
thanks in advance !
in broad terms, need model game state such can "advance" given increment of time, , then, during each cycle of main loop, determine how time has elapsed (typically small fraction of second) , advance game state much. how games appear work smoothly regardless of frame rate.
the interval becomes scaling factor on movement. example, if snake moving forward @ 5 units of distance per second, , during main loop find 0.01 seconds have elapsed since last time snake moved, advance snake (0.01 * 5) unit of distance during loop.
Comments
Post a Comment