Anyway or structure to let me update certain logic at 60 time per second and certain logic at 120 time per second?
You could always update at 120 Hz and do the second logic only once every two updates ?
pseudo code:
void updateAt120()
{
logic1();
if (frame % 2 == 0) logic2();
}
Put it after you create the graphics device before you update or draw.
I stick it in a method and call it at the bottom of load with other setup stuff.
double desiredFramesPerSecond = 120d;
this.IsFixedTimeStep = true;
this.TargetElapsedTime = TimeSpan.FromSeconds(1d / desiredFramesPerSecond);
graphics.SynchronizeWithVerticalRetrace = false; // if desired not too important nowdays syncs maximum draws per second to the monitors refresh frequency in hertz.
graphics.ApplyChanges();
Then as filnet said.
Alternately you can just time a seperate method yourself.
double desiredUpdatesPerSecond = 60d;
double updateFrequency = 1d / desiredUpdatesPerSecond ;
double now =0f;
double last = 0;
// then in update.
protected override void Update(GameTime gameTime)
{
now = gameTime.TotalGameTime.TotalSeconds;
if ((double)(now - last) >= updateFrequency )
{
last = now;
PacedUpdate(gameTime);
}
base.Update(gameTime);
}
public void PacedUpdate(GameTime gameTime)
{
}
Note you don’t have to make a second method. You could just execute your update code within that block in update. This way is just to show that you could have multiple different timed update methods that execute at different rates.
if you used both of the above then you would have 2 draws per update at 120 Draws per second and PacedUpdate would be called 60 times a second.
You could make it a little more exact and make up for lag or a stutter ect but thats the basic jist of it.
Thanks very much, will test on it