How to apply timedelta

Good Day Everyone, I was practicing to make an endless runner game for android devices, apparently there is a tip from the gdevelop wiki page about framerates(dont know if this is the right term) basically “timedelta”. How can I use timedelta in my own event sheet?
Here is the images. Thank you for the reply

The problem with using a fixed pixel change in position is that when the device is running slowly, the animation is slow. And when the device hums along, the animation is fast. This is because the fixed number of pixels are being added per frame. If the device is running at 20 frames per second, movement will be 1/3 the pace when the device is running at 60 frames per second.

The idea of using TimeDelta() is to create a smoother movement at the same speed/rate no matter how fast/slow the device is. Broadly speaking, TimeDelta() returns the fraction of a second that has passed since the last frame was drawn. You then move this fraction of your pixels per second.

In your example, instead of

work out how many pixels of movement you want per second. Let use 240 as the example (60 fps * 4 pixels per frame = 240 pixels per second). Set the scroll variable to 240, and update the positions with:

This will create the same speed game no matter what device it’s on, or what the frame rate is.


1 Like