locked
How do I make a Timer? RRS feed

  • Question

  • How would I make a timer in XNA?  I can't see how to use Game.ElapsedTime.

    The only thing I could find was GameClass.TargetElapsedTime.

    Help?

    Sunday, April 29, 2007 12:25 AM

Answers

  • The Game.ElapseTime is to be used in the update function. It tells you the number of ms since the last invocation of the update function. So you need to know how fast your objects will be moving: each object on the screen is moving at some rate X pps (pixels per second). Therefore you can convert the ElapseTime to seconds to compute how many seconds have elapsed since the last call to update. Your objects then would move pixels = pps * ElapseTime/1000 (based on the distance = rate * time formula). Therefore, there is no need for a timer like in other game libs.

    See the link: http://msdn2.microsoft.com/en-us/library/bb203878.aspx


    Sunday, April 29, 2007 1:44 AM

All replies

  • The Game.ElapseTime is to be used in the update function. It tells you the number of ms since the last invocation of the update function. So you need to know how fast your objects will be moving: each object on the screen is moving at some rate X pps (pixels per second). Therefore you can convert the ElapseTime to seconds to compute how many seconds have elapsed since the last call to update. Your objects then would move pixels = pps * ElapseTime/1000 (based on the distance = rate * time formula). Therefore, there is no need for a timer like in other game libs.

    See the link: http://msdn2.microsoft.com/en-us/library/bb203878.aspx


    Sunday, April 29, 2007 1:44 AM
  •  

    Thanks
    Sunday, April 29, 2007 2:17 AM