Results 1 to 6 of 6

Thread: Game Time

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Game Time

    I'm in the process of designing a game, how can i make the game tick over in time?

    First thought would be a timer but is this the correct way?

    Also I'm looking at building this game in WPF, By memory WPF does not have the timer control, what would you do then?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Game Time

    If you're talking about the System.Windows.Forms.Timer then, as the namespace suggests, it is intended to be used in Windows Forms. That said, its not a control, but rather a component, so there shouldn't be any issue using it in WPF. Regardless, you can always use the System.Timers.Timer anyway.

    Beyond that, you might have to explain what you mean by "tick over in time". A Timer is used like an alarm clock, not like a stopwatch. It raises an event at regular intervals, allowing you to execute code every N milliseconds, just like an alarm clock goes off at the same time every day, allowing you to do the same thing regularly at an interval.

    If you want to actually determine how much time has passed then that's a job for the Stopwatch class. Alternatively, you can just subtract one DateTime from another to get a TimeSpan, which describes the time period between the two points in time.

    You might possibly use the two together, with the Timer raising a Tick/Elapsed event, say, every second and, in the event handler, using a Stopwatch to determine how much time has passed since a reference point or how much time is remaining until a reference point.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Game Time

    I guess what I want to know is how would a game progress in time?

    I would want to speed the time up and slow it down, that is "artificial game time" i'm talking about. THe game design is much like the Sim City series whereby you want days, months years pass by.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Game Time

    You can base your game time on real time or on game actions. If it's game actions then the answer is fairly obvious. If it's real time then you measure real time and multiply that by some factor. If you want game time to move twice as fast as real time then you multiply by 2. If you want game time to move half as fast as real time then you multiply by 0.5. Etc.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    Re: Game Time

    HOw would you make the time move fast? isn't realy time just that real time?

    ALso how would you call an event at a intervil such as 01Jan or 30Jun

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Game Time

    All the information you need has already been provided. You use a Timer to make something happen at a specific time. You use a Stopwatch to measure elapsed time. You can also subtract Dates to get time periods.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width