fps question
sure u can. just use a timer functions to do this.
ie.
while(game)
{
...
 timer(10);
 update_scene();
...
};
so after 10 ms, the scene gets updated. therefore your frame rate will be 100fps (for all the computers that can handle this speed)....use a lower fps for lower speed computers...or better yet, make it a changeable option.
the other option is vsync, which modifies the fps to match the vertical retrace of the monitor. usually (60-85Hz/fps)
ie.
while(game)
{
...
 timer(10);
 update_scene();
...
};
so after 10 ms, the scene gets updated. therefore your frame rate will be 100fps (for all the computers that can handle this speed)....use a lower fps for lower speed computers...or better yet, make it a changeable option.
the other option is vsync, which modifies the fps to match the vertical retrace of the monitor. usually (60-85Hz/fps)
humm...
it''s better to time the stuff, rather then just having a hard pause like that....
...you get the idea.
or (even better!) you could do a framerate independent idea...but i''m not exactally sure how you would do it...
it''s better to time the stuff, rather then just having a hard pause like that....
for(;;{DWORD StartTime = GetTickCount();DoStuff()if(exit)break;while(GetTickCount() - StartTime > (FPS/1000)){//do nothing}}
...you get the idea.
or (even better!) you could do a framerate independent idea...but i''m not exactally sure how you would do it...
Programmers of the world, UNTIE!
Well, if you want framerate independent motion, create your game objects with velocities and/or accelerations in a convenient unit like pixels/second. Then, update your objects by passing them a delta (that is, the amount of time that has passed since the last frame was drawn). This creates framerate independent motion, I believe.
Summary: Pixels to move = velocity * change in time; cast positions to int when you''re drawing to the screen. The change in time will vary with each processor, but the movement will still be at the velocity you choose.
Actually, I had a hard time implementing this in Java, and had to use a sleep timer hack along with this method. But then, I have no graphics so far, just rectangles and circles and stuff. Maybe it''s just drawing frames way too fast....
Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,
fasting, good works and so on. Up until Doom, no one seemed to have thought about the
double-barrel shotgun. Eat leaden death, demon...
-- Terry Pratchett
Summary: Pixels to move = velocity * change in time; cast positions to int when you''re drawing to the screen. The change in time will vary with each processor, but the movement will still be at the velocity you choose.
Actually, I had a hard time implementing this in Java, and had to use a sleep timer hack along with this method. But then, I have no graphics so far, just rectangles and circles and stuff. Maybe it''s just drawing frames way too fast....
Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,
fasting, good works and so on. Up until Doom, no one seemed to have thought about the
double-barrel shotgun. Eat leaden death, demon...
-- Terry Pratchett
Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,fasting, good works and so on. Up until Doom, no one seemed to have thought about thedouble-barrel shotgun. Eat leaden death, demon... -- Terry Pratchett
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement