[XNA] Timer?

Started by G_G, March 08, 2011, 07:22:57 pm

Previous topic - Next topic

G_G

Even though I'm working on ARC I'm still working on GreGoR, just not as much as I've been wanting to. I would still like to have my own RPG engine. Anyways so I'm trying to create a timer class to make keeping track of time easier to access. So I created this timer class yet I'm not entirely sure if it works only because I don't have a solid project to test it in. But maybe I could get some pointers or possibly a tester.
namespace GreGoR
{
    class Timer
    {
        int miliseconds = 100;
        int interval = 0;
       
        public event EventHandler TimerTick;
        public Timer(int inter)
        {
            miliseconds = inter;
        }

        public void Update(GameTime gameTime)
        {
            interval += gameTime.ElapsedGameTime.Milliseconds;
            if (interval > miliseconds)
            {
                interval = 0;
                if (TimerTick != null)
                    TimerTick(this, new EventArgs());
            }
        }
    }
}

Its a repeating timer. When the timer reaches over miliseconds it resets and calls the TimerTick event handler. Maybe theres a better way to do this?

winkio

wait, what is the purpose of this timer?  You should be able to use GameTime for pretty much everything, and there is a class called Stopwatch in case you need something more general.

G_G

Its so I can tell when specific time intervals have passed when and where needed. The stopwatch class sounds more like what I need. Thanks winkio.

Tazero

Question are you making an rtp using rmxp format? cuz I would love to help with GFX/Sound/etc. :3


If you were a fish...