~BenDilts( void ); Please Help !
I''m just walking trough the messages, and i found a thing
that interesting me too!
About "run fps as fast as it possible, but adjust movement speed !"
Please, could you help me, i''m trying to solve this about a month !
Thanks.
(CRYP) -= F.O.T.N.G.G. =-
Cryp
I assume you mean have your character move across the screen at a constant rate, regardless of framerate.
This is fairly easy to do, but requires that you have some method by which to keep track of the time that passes for each frame. To do this, remember your physics equations for movement:
X = Xo + D
D = V*t
V = Vo + A*t
So, X = Xo + V*t
X is the position on screen
Xo is the last position on the screen
D is the distance moved during a time slice
V is the velocity of the object
Vo is the last velocity (if acceleration is used)
A is the Acceleration of the object
t is the time per frame (or, the time passed since the last one)
When first writing movement code, you actually use these equations without thinking about it. You probably already have code like:
if you think about it, what you''re actually doing with the above code is using the equation X=Xo+V*t with a t of 1.
If you can keep track of how much time has passed per frame, use that instead. What you''ll end up with is a (probably smaller) distance moved per frame, but no matter how fast or slow your frames are, everything that uses these equations will move properly based on your velocity.
With a delta time being kept track of, the above code looks like:
to keep track of the time per frame, use semi-accurate timing functions such as QueryPerformanceFrequency and QueryPerformanceCounter.
hope this helps a bit
*oof*
This is fairly easy to do, but requires that you have some method by which to keep track of the time that passes for each frame. To do this, remember your physics equations for movement:
X = Xo + D
D = V*t
V = Vo + A*t
So, X = Xo + V*t
X is the position on screen
Xo is the last position on the screen
D is the distance moved during a time slice
V is the velocity of the object
Vo is the last velocity (if acceleration is used)
A is the Acceleration of the object
t is the time per frame (or, the time passed since the last one)
When first writing movement code, you actually use these equations without thinking about it. You probably already have code like:
if(forward)
Xpos += X_MOVEMENT_SPEED;
else
Xpos -= X_MOVEMENT_SPEED;
if(up)
Ypos += Y_MOVEMENT_SPEED;
else
Ypos -= Y_MOVEMENT_SPEED;
if you think about it, what you''re actually doing with the above code is using the equation X=Xo+V*t with a t of 1.
If you can keep track of how much time has passed per frame, use that instead. What you''ll end up with is a (probably smaller) distance moved per frame, but no matter how fast or slow your frames are, everything that uses these equations will move properly based on your velocity.
With a delta time being kept track of, the above code looks like:
if(forward)
Xpos += X_MOVEMENT_SPEED*dt;
else
Xpos -= X_MOVEMENT_SPEED*dt;
if(up)
Ypos += Y_MOVEMENT_SPEED*dt;
else
Ypos -= Y_MOVEMENT_SPEED*dt;
to keep track of the time per frame, use semi-accurate timing functions such as QueryPerformanceFrequency and QueryPerformanceCounter.
hope this helps a bit
*oof*
*oof*
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement