Okay, this is really bad. Clearly, a hard-coded "2" that's applied to my character's "Left" property on every frame render isn't going to cut it.
Obviously, the game will run slow on crappy hardware, and there's not much I can do to prevent that. But the game shouldn't run faster on really good hardware! How can I cap the movement speed, or better yet, guarentee a certain speed within reason
I can already calculate frames per second, and how much time has elapsed between each render, so I'm sure it's just some simple multiplication thing I have to do from there... but math was never my strong point! How do I do this

Players move faster at higher framerates
Neil Waldie
remedy
amount_moved = speed / fps
Gustyn
That might work... except I only want the program to sleep if it has extra frames to burn off. So, I've got my fps already calculated...
if( fps > 30 ) // I want 30 fps
{
Sleep( /*timeInterval*/ );
}
How do I calculate the time interval, then Especially since fps might change...
Arie Jinich
gdekens
Actually, you know what It would be a heck of a lot easier if I actually could cap my rendering at a certain rate... like 50fps or something. Then I wouldn't have to factor the fps into every movement equation; I could just force the screen to only render at a certain rate.
Any idea as to how to do this
Sunil Agarwal
I don't think DirectX Managed or not cap the frame rate
In the present parameters you have one of the value
to set to Sync with vertical refresh rate or to Present immediatly
There is two mode, if you tell to wait the Vertical Sync if will caps at the frequency
your Screen resolution is set to...so in your case at 75 hz
But if you tell the Render in the present params to present immediatly whenever he finish his drawing the fps will go very much faster
The draw back is that you will see some tearing because the flip of the present will happen between vertical sync of your screen...But this tearing happen only sometime and when you are moving (otherwise you draw without change so their is no tearing when there is no move)
The_Oracle
Camms
Okay, one thing... the following code limits the framerate to "60", most of the time...
if (Timer.FPS > Phy.FpsCap) // Phy.FpsCap is 60; Timer.FPS constantly updates
{
int timeInterval = (int)( (float)( 1000 / Phy.FpsCap ) - _elapsed );
System.Threading.Thread.Sleep( timeInterval );
}
Unfortunately, the framerate is still jumps to 75 at erratic intervals, causing sudden bursts of rapid movement. Is there a way to bullet-proof this technique further, so that the framerate can NEVER exceed 60
ttp52
Capping your framerate or assuming a framerate will probably end up getting you into trouble if you ever lose a frame.
Take a look at the SDK framework samples expecially at the Update() callback.
When you start your game start a timer (an accurate one! use the Stopwatch class in .Net 2.0 which wrapps the QueryPerfCounter PInvoke that is usually given as an example) and then every frame work out how long it has been since your last frame. That gives you the time delta - use this as your speed multiplier.
Then you are back to your original forumla of pixels per second for your speed.
How to convert your '2' Well what does the 2 mean to you. DO you want your sprite to cover 100 pixels in 5 seconds Is that what the 2 means on your nice gamer rig In that case then your 2 means 100/5 = 20 pixels per second. So replace the 2 with 20, multiple by the time delta between frames and the speed of your sprite is locked.
kempshall
Jeffory
Troy Cui
timeInterval = 1000/30 - (time it took to move stuff);
glenberry
pablo_q
PS, it would seem that managed DirectX caps your FPS at about 75, anyway.
But I'd still like a way to scale my speed to my fps, so that my laptop (which gets 50fps) and my desktop (which gets 75fps) can play the game at the same speed...
Is there a way to convert my hard-coded "2" into an expression of "pixels per second", or something
Any help will be greatly appreciated!