speed vs. fps
I''ve seen in many posts that when moving bitmaps, people divide a speed by a value ''fps'', frames per second.
Ex. mover.xpos += mover.velocity/fps
Is this necessary? Why are they dividing by the frames-per-second? And how do they get the value for fps anyway?
No, Canadians DON'T all live in igloos. They live in one BIG igloo!
They do it to produce (what looks like) frame-rate independant movement.
If they have a speed in units per second, and they divide it by frames per second, then it will give them a speed in units per frame. When the fps changes, the speed in units per frame also changes, but the speed in units per second stays the same.
It is not the only way to provide frame rate independant movement though.
There are also at least two methods of producing the fps. One way is simply to divide the number of frames you''ve drawn with the time it took to draw them (in seconds).
John B
If they have a speed in units per second, and they divide it by frames per second, then it will give them a speed in units per frame. When the fps changes, the speed in units per frame also changes, but the speed in units per second stays the same.
It is not the only way to provide frame rate independant movement though.
There are also at least two methods of producing the fps. One way is simply to divide the number of frames you''ve drawn with the time it took to draw them (in seconds).
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
If you have an object moving 10 units every frame, like this:
The object will move at different speeds based on the framerate. If the game is running at 60 frames per second, then the object will move about 600 units in one second (10 * 60). If the game is running at 30 frames per second, then the object will move 300 units in one second (10 * 30), half as fast as it was before.
By dividing the velocity by the framerate, the amount of time it takes to move from one point to another is exactly the same regardless of framerate.
Using the above example, if you have this:
If the framerate was 60, 10/60 = 0.17 units per frame, which is 10 units per second (60 * 0.17). If the framerate was 30, 10/30 = 0.33 units per frame, which is still about 10 units per second (30 * 0.33).
[edited by - SilentCoder on March 16, 2002 9:46:45 PM]
mover.xpos += 10;
The object will move at different speeds based on the framerate. If the game is running at 60 frames per second, then the object will move about 600 units in one second (10 * 60). If the game is running at 30 frames per second, then the object will move 300 units in one second (10 * 30), half as fast as it was before.
By dividing the velocity by the framerate, the amount of time it takes to move from one point to another is exactly the same regardless of framerate.
Using the above example, if you have this:
mover.xpos += 10 / fps;
If the framerate was 60, 10/60 = 0.17 units per frame, which is 10 units per second (60 * 0.17). If the framerate was 30, 10/30 = 0.33 units per frame, which is still about 10 units per second (30 * 0.33).
[edited by - SilentCoder on March 16, 2002 9:46:45 PM]
That''s nice, but how do I get the frame-rate? Is "fps" a special variable or something? Or do I set it?
No, Canadians DON'T all live in igloos. They live in one BIG igloo!
fps is the number of times you update the contents of the screen, usually by flipping a backbuffer to the screen. The fps value is dependant on how fast you can draw everything, so if it takes 1/10 second to draw 1 frame, my fps will be 10. The basic method of calculating fps is to count the number of frames drawn (say I''ve counted 60 frames) and divide it by the number of seconds that have elapsed (I started drawing frames 2 seconds ago). 60 frames/2 second=30 frames/second.
fps is the number of frames you''re drawing each second. If you time each frame in milliseconds, then you can just divide 1000 (one second) by the total frame time. So, if a frame takes 16 ms to draw, 1000/16 = 62.5 fps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement