I’m using C# and XNA. And there’s this method in Game class
Update(GameTime gameTime)
I need to execute my function inside this method about 4 times per second. How can I acheive that?
So far I could only know when new second starts by doing
if (gameTime.TotalGameTime.Milliseconds == 0)
But I need a way to run my function some specific times per second. But I can’t figure out how I can do it…
You need to keep a separate counter, and the interval at which to call your function. For 4 times a second, this is
float interval = 1/4;.Every frame, update the counter by the number of milliseconds that have passed since the last frame.
Check if this counter is greater than interval; if so, at least
intervalseconds have passed and the function needs to be called.