Im creating a simple vehicle and projectile simulation game in WPF using C#. I need to have a constant frame rate (i.e. i need to know how much to move an object with a certain velocity in each frame). This way I could subscribe an event which calculates and updates positions according to the game's physics to the CompositionTarget.Rendering event.
CompositionTarget.Rendering += UpdatePositions;
I googled it a while, and found no answer. The fps in WPF seem to be arbitrary, and using a Stopwatch to know how much time elapsed between a frame and the previous one wouldn't be clean at all.
I thought also of creating my own frame rate, by calling UpdatePositions every some amount of milliseconds and hoping for the Rendering to occur accordingly and have a smooth animation. This seems like reinventing the wheel, and I cant think of a way of implementing this in a clean and simple manner.
Thanks!