Game Development Community

Timer

by Levi Putna · in Torque X 2D · 10/27/2007 (9:26 pm) · 2 replies

Is there an easy way to call a function after an amount of time bas passed?

E.g
TimeSpan delay = TimeSpan.FromSeconds(3);
elapseTime(delay,someFunction());

with delay being the amount of time and someFunction() being the function to call after the time has passed.

I want to have a 3 second delay between finishing one level and loading another.
I currently have a rather complicated while loop doing the job.

Thanks in advance.

#1
10/28/2007 (12:06 am)
Sounds like a perfect case for the ScheduledEventPool. First, create a delegate method to be called.

public void MyScheduledFunction(object sender, ScheduledEventArguments scheduleEventArguments)
{
     //DO SOMETHING
}

Next, schedule the call into MyScheduledFunction for some future time, say 3 seconds (or 3000 ms).

Game.Instance.Engine.RealTimeSchedule.Schedule(3000, MyScheduledFunction);

That should do it...

John K.
#2
10/28/2007 (1:41 am)
Thanks,
That as exactly what I was looking for.