Perfect Timing!
-
Hi all, I need to move a sprite exactly 100 pixels every second regardless of the framerate. Any help would be great ..thx.
pokabot wrote:
I need to move a sprite exactly 100 pixels every second regardless of the framerate
The simple answer is to obtain the current framerate and move the sprite by 100/framerate but what happens if the framerate falls below 1 FPS?
-
pokabot wrote:
I need to move a sprite exactly 100 pixels every second regardless of the framerate
The simple answer is to obtain the current framerate and move the sprite by 100/framerate but what happens if the framerate falls below 1 FPS?
-
Hi all, I need to move a sprite exactly 100 pixels every second regardless of the framerate. Any help would be great ..thx.
All games work this way, they move the sprites based on time passed, and render as many frames as the processor lets them. So, the key answer is, don't write any code that changes any values just because a render event has occured.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
All games work this way, they move the sprites based on time passed, and render as many frames as the processor lets them. So, the key answer is, don't write any code that changes any values just because a render event has occured.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi all, I need to move a sprite exactly 100 pixels every second regardless of the framerate. Any help would be great ..thx.
you need an accurate timer (there is one in DXUtils class in DirectX SDK) and define your move formula depend on time and speed just like X=Vt+X0 for example if X0=0 and V=100px/sec then in 2Sec it would be 200px or in 0.01 sec it would be just 1px so it does not depend on the framerate you can take two approach depends on your need 1- X0 would be always zero so after 10 sec you pass the 10sec to formula 2-use time Elapsed method (use in most games) you can calculate the elapsed time using the timer and the previuos position would be X0. for example if X0=0 and V=100px/Sec after one sec X=100px and after 1.5 sec from beginning it would be X0=100px ,V=100px/sec,ElapsedTime=0.5 sec X=100*0.5+100=150px and if you are doing it in the 3D you must define each speed for every dimension or calculate them thruogh total speed using math and ofcourse you involve acceleration too. hope the post would be useful