Jump to content
  • Advertisement
Sign in to follow this  
Diirewolf

How to use Timing with C# mdxutil.cs timer

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok im not sure if this is in the right section of the forums... anywayz im coding a 2d engine using C# and Managed DirectX. My problem is with timing. First I have my timer class set up (copied from mdxutil.cs in the DirectX SDK). It works fine. Now my problem is how do I use the timer. Ok first of all, I have a Sprite class with an Update(double absoluteTime) method. ok now I call this in my game loop and pass the absolute time to every sprite. Now lets say I want the sprite to move (according to its velocity) 5 times a second, and I want it to go to the next frame of animation every 2 times a second. How would I use the timer to accomplish this? thanks

Share this post


Link to post
Share on other sites
Advertisement
If you pass the absolute time (useful if say your not updating every object every frame) then each object would independently store the last timestamp that it updated. You can then calculate the elapsed time simply by subtracting the 'last updated' time from the 'current absolute' time.

In my game, speed is specified in meters per second. In my update sub I divide the speed by 1000 to make it per millisecond (I dont do that per-frame of course, just when the objects is instantiated or the speed changed). I can then multiply the per-millisecond speed by the elapsed milliseconds.

Share this post


Link to post
Share on other sites
so the only way to do it would be to have separate variables for animation update and movement update ie. float lastAnimUpdate; float lastMoveUpdate;
I saw another game do it in a different way but i dont remember how. Are you sure this is the only way to do it?
thx

Share this post


Link to post
Share on other sites
You wouldn't really need 2 variables to store the last update unless you have 2 functions, one for physics/state/etc, and another for animations.

If those are both handled by 1 function, as they are in a lot of games I've seen/written, you'd just store the timestamp for the last Update call.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!