delta_time

The time passed in microseconds between one step and another.

Syntax:

GML Code Example

delta_time


Returns: Real


Description

The purpose of delta timing is to eliminate the effects of the lag or slowness of computers that try to handle complex graphics or a lot of code. It is a value that can be added on to the speed of objects so that they will eventually move at the same speed, regardless of lag. This is achieved in GameMaker: Studio by using the read only variable delta_time every step as it measures the time that has passed between one step and the next in microseconds (1microsecond is 1,000,000th of a second). Therefore the variable delta_time can be used to calculate how much faster (for example) a game character has to move to make up for a lag spike in the game.


Example:

GML Code Example

speed = spd * (ot - delta_time);

The above code will set the speed of the instance using delta-time to correct for lag. The variable "ot" would be used to hold the previously calculated delta_time value so that the ratio can be used to multiply the base speed value (held in the variable "spd") and so get a consistent speed for the instance.





No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here