Chaos Project

Game Development => Sea of Code => Topic started by: G_G on March 08, 2011, 07:22:57 pm

Title: [XNA] Timer?
Post by: G_G on March 08, 2011, 07:22:57 pm
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?
Title: Re: [XNA] Timer?
Post by: winkio on March 08, 2011, 07:26:39 pm
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.
Title: Re: [XNA] Timer?
Post by: G_G on March 08, 2011, 07:36:34 pm
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.
Title: Re: [XNA] Timer?
Post by: Tazero on March 17, 2011, 07:15:51 pm
Question are you making an rtp using rmxp format? cuz I would love to help with GFX/Sound/etc. :3