Slow Down?
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?
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).
I can do what Rhone Ranger suggested, how do u lock the fps?
-Dan
Yes I realize im a n00b...
-Dan
Yes I realize im a n00b...
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...
---
shurcooL`
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.
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; }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement