Skip to content
EinBurgbauer edited this page Mar 21, 2021 · 6 revisions

Description

Time lets you access and get many timing related values at the core of the framework. The time values are not necessarily equivalent to real time and will - in the worst case - slow down along side the application.

FPS Target and Minimum

The game tries to run at the frame rate of Time.TargetFPS. The default value is 60, setting it to 0 removes an upper limit, but remember that when System.Window.VSync is enabled, the frame rate might also be limited to (60, mostly) by that. If the a frame is completed faster than the duration of a frame at this frame rate, the thread will sleep for the remaining time.

Time.MinFPS limits how much the game tries to catch up. The default value is 20, setting it to 0 effectively removes a lower limit. It's basically an upper limit to delta times. The game will run at least at this theoretical frame rate, even when the actual frame rate is lower than that. Thus the game will slow down. If the actual delta time is higher than the duration of one frame at this frame rate, Time.RawDelta will be set to the later. This should keep very high delta time values from breaking parts of the game.

Loop time

Time.Delta is the time since the last frame. Time.Duration is basically all the accumulated delta time. These values are multiplied with Time.Scale. The raw values have a "Raw" prefix, like Time.RawDelta.

So, for frame rate independent operations, multiply values with Time.Delta or its raw version to keep it approximately the same

const int speed = 300;
position.X =+ SPEED * directionInput * Time.Delta;

Freeze

Time.Freeze(...) can quite literally freezes the game for a given period of time.

Time.Delta will be 0 while frozen and Time.Duration will not increase, just like when setting TIme.Scale to 0. But most importantly, Game.Update() will not be called at all (but Game.Step() still will be).

FixFPS

Disables variable timestep (which happens in any case when TargetFPS == MinFPS) and lets the game simulation run at a constant Time.Delta. The game will slow down when the real frame delta time is higher than the now constant Time.Delta as described in the section about Time.MinFPS above. Setting either TargetFPS or MinFPS to a value other than the values set in the FixFPS call, will the return the game to running a variable time step.

Interval

Interval methods return true on or between a given interval. Userful for regular impulses for timing stuff, like spawning particles while walking.

Clone this wiki locally