|
-
Feb 4th, 2011, 05:16 PM
#1
Thread Starter
Fanatic Member
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?
-
Feb 4th, 2011, 08:34 PM
#2
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.
-
Feb 5th, 2011, 02:56 PM
#3
Thread Starter
Fanatic Member
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.
-
Feb 5th, 2011, 07:42 PM
#4
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.
-
Feb 5th, 2011, 08:03 PM
#5
Thread Starter
Fanatic Member
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
-
Feb 5th, 2011, 08:45 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|