Lightweight delta timing solution for GameMaker: Studio 2
# Delta Timing
Delta timing is a method of manipulating game components based on real time rather than steps. In GameMaker, when a user is unable to run your game at the desired step speed, it will run visibly laggy. Delta timing helps to fix this, by scaling movement, alarms and everything else based on how long it actually has been since the last frame.
This resource provides tools to make delta timing nearly trivial in GameMaker.
Delta exposes a small number of scripts to help with timing:
Initializes the delta timing. Call this as early as possible in your game, before anything requires delta timing. You can also find configuration values in the definition of this script.
Call this script on the
begin step event of a game controller - likely a persistent object that is in every room of the game. This updates the delta timing for use in other scripts.
The bread and butter of Delta. Returns the given number modified for the delta timing.
This works by multiplying the provided number by the current "step factor", a number representing how many "frames" have passed in actuality. For example, if your game is running at half the speed it should be, the factor would be
2, since things need to move twice as fast to appear normal.
// Keep speed smooth between frame slowdown speed = d(movespeed); // Keep the animation running smoothly image_speed = d(1); // Tick down a timer in real-time instead of frame count someTimer -= d(1);
A utility function to return the given number in frames that would constitute that many seconds. Useful for setting timers in real seconds. This function uses your current game speed to determine the result.
Sets the maximum multiplier for Delta to compensate for lag with. Default is 3. Setting this to a higher number will handle larger lag spikes, but may cause erratic behavior.
Delta exposes an object parent which automates delta timing for most usages: movement, gravity, friction and alarms, even integrating natively with alarm events!
DeltaObject to your game, then for any object which requires delta timing, set
DeltaObject as the parent.
DeltaObject, you will need to use
event_inheried() on the following events (if the child object has its own version of these):
- End Step
Once you have set your object to inherit from
DeltaObject, you can use the following instance variables in place of their counterparts to get delta timing for free!
These values will be converted into the correct values for delta timing, and managed internally to the object, then set as their GameMaker equivalents. When using these variables, do not use the GameMaker equivalents as well.