FrameRate dependant movement

Started by
26 comments, last by bobason456 18 years, 8 months ago
Quote:Original post by EvilKnuckles666
ok, i have everything running correctly with the frame dependant movement using timeGetTime() but things still look choppy at times... is there any other way or something i'm doing wrong?


What you mean by choppy?

im not quite sure how your define is suppsed to work. The further on through your code you go from the start of the main loop the bigger the FRAMEDELAY is going to be, so all the objects that you process last will move more than the objects you process first.



Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Advertisement
well, of course i make FrameDelay = timeGetTime() at the beginning of every frame. and it looks choppy like it moves fast then slow then fast then slow and i can actually see that happening. not really the frames, but it's not moving smoothly like i want it
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Quote:Original post by EvilKnuckles666
well, of course i make FrameDelay = timeGetTime() at the beginning of every frame. and it looks choppy like it moves fast then slow then fast then slow and i can actually see that happening. not really the frames, but it's not moving smoothly like i want it


i know but say you have 10 sprites you going to be multiplying each one by FRAMEDELAY whish will probably always be GetTickCount()-FrameDelay

so it will be:

Sprite 1: step value * (GetTickCount()-FrameDelay)
Sprite 2: step value * (GetTickCount()-FrameDelay)
Sprite 3: step value * (GetTickCount()-FrameDelay)
Sprite 4: step value * (GetTickCount()-FrameDelay)
Sprite 5: step value * (GetTickCount()-FrameDelay)
Sprite 6: step value * (GetTickCount()-FrameDelay)
Sprite 7: step value * (GetTickCount()-FrameDelay)
Sprite 8: step value * (GetTickCount()-FrameDelay)
Sprite 9: step value * (GetTickCount()-FrameDelay)
Sprite 10: step value * (GetTickCount()-FrameDelay)

but by the time you get to 10 GetTickCount will be returning a greater number than at the start so (GetTickCount()-FrameDelay) will work out to be a bigger number by the end of the frame then at the start.

What you need to do is measure the difference between frame times

so like at the start of each frame have:

oldframetime = newframetime;
newframetime = GetTickCount();
framedelay = newframetime - oldframetime;
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
awesome, everything works great now. but only in fullscreen mode, in windowed mode, things still look a little choppy. the game is going to be in fullscreen anyway, but for editting purposes it in windowed mode. is the choppyness just something i'm going to have to deal with in windowed mode or can i fix that too somehow?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
... theoretically, shouldn't it never be choppy becuase i'm multiplying the differnt from frame to frame by the step???
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
When creating a game usually you would want to have a movement that is independent to framerate and not the opposite. The independent framerate movement allows the game to run at the same (phisical)speed on computers with different processing power.
If you want to have a smooth movement in your game you will have to chose between:

1.upgrading your computer.

2.use the computer with the same configuration but without GetTickCount()function.

Manipulating GetTickCount function will not give you a higher or a lower FPS. It will ony allow you to speed up character/camera movement in your game(that will be acomplished by skipping several frames on each movement step).




P.S. You can also improve your FPS by changing the screen refresh rate in Windows but I would not recommend that.

Edit: To rephrase what I have sad:
Don`t use GetTickCount function at all if you want a smooth sprite movement without upgrading.

[Edited by - Calin on August 4, 2005 8:41:37 PM]

My project`s facebook page is “DreamLand Page”

soooo... should i just have the have the sprite move there assigned step and for slower computers they will move slow and for fast computers they will move fast?? o.O

Is there a way to NOT use GetTickCount() and have sprites move independant of the speed of the computer, but still have the game run at it's top speed?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Let`s suppose you have a game with the following (pseudo) code:

if ( "Up Arrow" is being pressed)
Soldier.Xposition += 5; // moves the soldier 5 units on the X axis.

Now suppose that you run your game on a comp that has a 1000 Mhz processor. Also suppose that while you hold down the "Up Arrow" for 1 second your character walks 200 units. This means that during a second your comp has run 40 times ( 200 /5 ) through the game loop. This also means that the game has 40 FPS.

Now, if you take your game and run it on a 3000 Mhz Processor computer the game will run roughly three times faster: when the "Up Arrow" will be pressed for a second the character will walk 600 units instead of 200.

If you want to make your soldier walk 200 units/second in the second situation too, you will have to reduce the motion speed of character to compensate for the greater processing power of the 3000 Mhz computer. To put it another way, you will have to find a way to knot the soldiers movement speed with the computer speed. This is where GetTickCount ( or better QueryPerformanceCounter ) function comes useful. These functions help you find the amount of time nedeed for a computer to run once throught the game loop.

Here you cand find a short and easy tutorial on using QueryPerformanceCounter function.

Quote:Is there a way to NOT use GetTickCount() and have sprites move independant of the speed of the computer, but still have the game run at it's top speed?


The game should run at the top speed no matter wether you are using GetTickCount() or not. As I mentioned before the functions in question affect only the character/objects motion speed and not the frame rate of the game. GetTickCount() is not used to increase/decrease FPS. For instance, in the example above, you can make the your character move at 600 units per second on the 1000 Mhz comp by changing Soldier.Xposition += 5 to Soldier.Xposition += 15; however this does not cause a FPS increase. The FPS will remain the same (40 in our case), the only difference will be a much choppyer animation(the comp will use 1 frame for every 15 motion units instead of 3 frame for the same motion distance.)

I tryed to be as explicit as possible.
One last note: there might be 1000+ things that can cause a low FPS rate. The best advice I can give you is to run your game on another computer( a better one). If you still get low framerates most likely the problem hangs in your game code.

[Edited by - Calin on August 4, 2005 9:43:30 PM]

My project`s facebook page is “DreamLand Page”

First off as far as I can tell the “choppy ness” is due to a mismatch between the number of frames your app is trying to draw per second and the refresh rate of your monitor (if v-sync is on). Lets say your monitor refresh is 60 fps and your timer is not all that accurate – as it sounds in your case – and your actually drawing 59.5 frames per second so your half way through processing half a frame when the monitor is done it’s 60, so that frame may end up getting thrown away, not drawn at all or delayed. Because it’s probably quite hard to match any system timer with the monitor refresh timer, there may be an amount of phase difference that is causes the frame skips. The solution is turn off v-sync. Perhaps.

Wow I can’t believe no one has yet suggested using some simple maths to solve your movement problem. Remember that if you travel 1 meter in one second then your speed is 1m/s ? So why not give all your objects velocities then calculate the actual distance covered

V = d / t [EDIT: * <> / opps]

So

d = v * t

You know t, don’t you because you are controlling how often frames get drawn. Using a timer, so it should all end up being independent of how fast the computer is.

[Edited by - bobason456 on August 5, 2005 10:18:45 PM]
that would work too, but i wouldn't know t becuase i want the cpu to output the maximum amount of frames, i know that for my copmuter, but i wouldn't know that for anyone else's computer so i would need to calculate that
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML

This topic is closed to new replies.

Advertisement