Archived

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

Slow Down?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey I have programed a simple pong game that runs well on my computer but when i run it on my friends computer which is super hooked up it runs SO fast that you can even see the ball. 200fps compared to my 77fps. How can i make my game run at the same speed no matter what computer it is on?

Share this post


Link to post
Share on other sites
timeGetTime() returns a millisecond count. you can use that and update the physics with the time elapsed since the last call to the physics update, and plug that into your physics equations (integrations).

Share this post


Link to post
Share on other sites
Not that you should, as that''s a poor technique, but you can do so easily too.

It''ll still require timers. All you gotta do is check that x amount of time has passed since the last frame, before continuing to the next one. Where x should be 1 / y, where y is the desired Frames per Second. For example, to achieve 100 FPS...

while (true)
{
last_frame_time = Timer.GetCurrentTime();

DoFrame();

while (Timer.GetCurrentTime() - last_frame_time < 0.1)
Sleep(0);
}


---
shurcooL`

Share this post


Link to post
Share on other sites
I agree it''s not good practice to lock the framerate, cause what about the cases where computers are running SLOWER than your locked fps? They will not be at the same speed.

BUT if you used time based movement, no matter how slow the computer is (or how fast) it will be consistent.


Just in case I haven''t convinced you though, I will expound a little on how you lock the fps.


float elapsedTime is time elapsed in milliseconds.

float LockedFPS=40.0f; //change this number for whatever you want.


float Modifier=0.0f;
float TimeToRender=1.0f/LockedFPS;

///////////////////////////////////
//in game loop
Modifier+=elapsedTime;
if(Modifier>=TimeToRender)
{
render stuff;
Modifier=0.0f;
}

Share this post


Link to post
Share on other sites