Slow Down?

Started by
6 comments, last by Mat1515 20 years, 4 months ago
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?
Ut o not me again:) lol
Advertisement
Lock the frames per second

OR use a timer for the movement.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
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).

Everything is better with Metal.

I can do what Rhone Ranger suggested, how do u lock the fps?

-Dan

Yes I realize im a n00b...
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
how dooo you lock FPS?
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`
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 loopModifier+=elapsedTime;if(Modifier>=TimeToRender){   render stuff;   Modifier=0.0f;   } 
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno

This topic is closed to new replies.

Advertisement