Delta time refers to the time that has passed since the last frame was rendered. In GameMaker, this can be incredibly useful for creating frame rate independent motion and animations. To use delta time in GameMaker, you typically access the
delta_time built-in variable.
Here is an example of how you might use
delta_time to move an object at a consistent speed regardless of the frame rate:
delta_time variable holds the number of microseconds since the last step event, so by dividing by 1,000,000, you turn it into a value representing the number of seconds passed. This enables you to calculate movement or animations based on time rather than frames, which can lead to smoother and more consistent behavior across devices with different performance characteristics.
When using delta time, it's important to also consider any potential maximum step size to avoid issues with very large delta times (e.g., when your game is resuming from being paused). You can handle this by capping the delta time:
This ensures that even if a large delta time occurs, your object will not move an unexpectedly large distance.
Be aware that
delta_time affects all time-based calculations, so you should use it consistently throughout all parts of your game that depend on timing for consistency.