GETTING STARTED IN GODOT – PART 4 – DELTA By Alex K. Whenever you play a game, some frames might be slower to process
than others. This might be due to the
complexity of the frame’s code, or simply due to something else running on
your computer in the background.
Slower frames lead to lag and could even lead to inconsistency in the
game. In this short guide, we will look at an easy way to avoid the
lag described above. 1.
Notice the _process function has a parameter named delta. It is
the amount of time in seconds that has elapsed since the last frame.
2.
We can test to see the value of delta by temporarily adding a
print statement inside _process. Note that this can be
done even if you already have code in _process. I
simply placed it at the top of the function. 3.
Run
the program. You should see an output
value each frame that is close enough to the decimal value 0.016666666667
which is 1 / 60. This is because our
game is running at a frame rate of 60 frames per second.
4.
Let’s
consider the _process function code that we wrote last guide and change all
of the movement amounts from 10 to the new 10
* (delta * 60). 5. Test your program.
It should still work like it did before but it is now lag proof. 6. You can now delete the print(delta) line. |