Archived

This topic is now archived and is closed to further replies.

heeeeeeeeelp meeeeee!

This topic is 6674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

how would i make an object with a decreasing velocity move the same distance when the frame rate is not constant? this is something like what i do and it''s not working for me: QueryPerformanceCounter(&bb); velocity.x -= .1f*(bb.QuadPart - aa.QuadPart); if ( b.v.x <= 0) velocity.x = 0; QueryPerformanceCounter(&aa); object.x += velocity.x;

Share on other sites
I think basically what you want to know is how to keep the game speed constant, based on normal time (real seconds), not on the speed of the game (frames per second), right? In my program, I have a small timer function to record the length of each frame in seconds (into a variable called FrameLen). What I do is base everything in the game off that, not off the number of frames that have gone by. So if you have an object moving 20 pixels per second (pps), each game frame you would move the object 20pps*FrameLen. So if your game is running at 50 frames per second, then each frame would be .02 seconds long, and therefore the object would move 20pps*.02sec, or .4 pixels per game frame. Or if you run it on a faster computer, say running at 100 frames per second, then the length of each frame would be .01 seconds, and the object would move 20pps*.01sec, or .2 pixels per game frame. So here is a basic equation:

float curSec=0, oldSec=0, frameLen=0;

void mainLoop()
{
object.x += velocityPerSecond*frameLen;
//
//the rest of your game code here
//

//these are the timers, run at the end of each game loop,
// recording the length of the frame and the number of seconds
// that have gone by since the beginning.
oldSec = curSec;
curSec = (GetTickCount()-tickZero)/1000;
frameLen = curSec - oldSec;
}

I hope this helps, I was pretty long winded.

Share on other sites
I wouldn''t use windows timers (too complicated)

#include
.
.
.
DWORD lasttime,currenttime=timeGetTime();
float timeoffset,fps;
.
.
.
// beginning of the draw proc
lasttime=currenttime;
currenttime=timeGetTime();
timeoffset=currenttime-lasttime;
fps=1.0f/(timeoffset/1000.0f);

"Everything is relative." -- Even in the world of computers.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 14
• 9
• 10
• 12
• Forum Statistics

• Total Topics
633003
• Total Posts
3009831
• Who's Online (See full list)

There are no registered users currently online

×