Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8759915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:55:15+00:00 2026-06-13T14:55:15+00:00

I am making an XNA game and it’s time to make daytime system and

  • 0

I am making an XNA game and it’s time to make daytime system and for that I need some kind of clock. I tried to use GameTime.TotalGameTime.Milliseconds == 0 to add one second to the second counter of my custom clock class, but it turned out that GameTime doesn’t always run through zero milliseconds. Using TimeSpan prevUpdate to compare to TotalGameTime.TotalSeconds doesn’t give enough precision, and the time is noticeably slower than the real time somehow.

What XNA or .Net component can I use to base my clock on so that it doesn’t cost too much resources or deviates noticeably from real time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:55:16+00:00Added an answer on June 13, 2026 at 2:55 pm

    Use Stopwatch for high-precision timing (reference).

    Use XNA’s GameTime for rendering and frame-to-frame timing logic. XNA’s timer does not match “wall clock” time exactly. It is able to drift in order to better line up with frame rendering, giving you smoother animation (this is behaviour is provided by the Game class). Over time it will deviate from real time slightly, but for most games this is not a problem.

    Use DateTime for measuring longer time spans accurately (eg: minutes, hours).


    Note that you shouldn’t compare Milliseconds == 0, because you cannot know exactly when XNA will call your Update method, so you could have Milliseconds == 999 on one frame, and then Milliseconds == 15 the next – wrapping around and skipping past 0, so your condition never triggers.

    So you need to determine when the timer crosses the threshold. There are many ways to do this. You could track a threshold (useful if you are tracking some “total” time), incrementing it after each trigger. Personally I prefer to accumulate time like so:

    seconds += gameTime.ElapsedTime.TotalSeconds;
    if(seconds > 1.0)
    {
        seconds -= 1.0;
        DoSomething(); // Triggered each second
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a game using XNA framework, so I use a lot functions that
I'm making a highscorelist for my XNA game. I would like to make it
I'm making a simple game in XNA (for Windows, if that makes a difference),
I'm making a game in XNA, and I noticed that when I publish the
So, I'm making a 3rd person game in XNA. I've created a camera that
I'm making an xna game and there is going to be many classes that
I'm making the skeleton for the typical BubbleShooter game in XNA, and I'm having
There I am making a 2D game in C# XNA 4.0, and run across
I'm making a simple game using the Windows Phone Silverlight and XNA Application type
I'm planning on making a casual word game for WP7 using XNA. The game

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.