program flow and timed events

Started by
2 comments, last by llloyd 20 years ago
I''m new to game programming, been doing web software and unix system programming for about 5 years. Trying my hand at some "one armed bandit" type games. I''m using managed directx and I have all the display stuff figured out nicely, input handling etc, but I''m missing something when it comes to the correct way to handle time delays. For example, someone clicks the "spin" button, I immediately generate the random numbers for the 3 results, but I don''t want to display them immediately, I want to light up a button for a second, then show each one with a delay between, then some sort of overlay if there is a winning combination or whatever. All the logic is done, graphics displaying etc, but this timing thing is confusing me. I obviously can''t use sleeps because that would destroy the rendering, should I be using threads? Any sites I should be checking or books reading for this kind of information? thanks in advance.
llloyd
Advertisement
Depends on how you''ve partitioned the problem. If the graphical objects have access to the information ( result and current time ) they can then query the current time and display the approritate state, and the logic can all be encapsualted into the graphical object. Such as a single collumn can have 3 states, waiting, spinning, and stopping. The waiting state just displays the last graphic , if there wasn''t one then a random graphic. The spinning would display a animiated spinning graphic, but also check the current time to see if it is greater than the stop time. If it is, it then transitions to the stopped state. The stopped state displays the result graphic. So when you enter the spinning state give it the appropriate spin duration. As the collumn move to the right, the spind duration increases by a factor of X, which will cause them to stop in sequential order.

If you wanted alittle more flexiblity, you an break out the logical element from the graphical elements. This is alittle more involved and proably doesn''t suit your problem. So i would switch with teh single object solution.

Good Luck!

-ddn
You could use the High resolution timers (info somwhere in these foums) or the "timeGetTime()" function. Then when an event
occurs, you save the current time. Then each frame you check that saved time against the current time for that frame, and
when a certain amount of time has elapsed you proceed one step
by displaying the next image, and repeat that process until you
have displayed the complete result.

Hope i wasn''t to vague in my description.
-------------------------------------------------Founder and DirectorAllSoft Studios
Use timers and a current time like the previous posters said, but take it even farther and have a currentGameTime. This would be read-only to everything but a specific timeUpdate() routine.

This way objects could time themselves easily (stopTime = currentGameTime + SPIN_TIME) but also gives you full control over the flow of time.

In your timeUpdate(), you could increment currentGameTime by the amount of real time that has passed or you could easily slow or speed it up. All objects should act consistently regardless of how the actual rate of passage of your game time (though you need a timeScaleFactor for interpolation). This also allows you to handle pausing and replays easier.

This topic is closed to new replies.

Advertisement